![]() It also enables you to debug requests from other people, so you might be able to find issues, you don’t “see” youself. Persistent records: If you have this “debug mode” activated, you can save the logged information into the file over a longer period of time and check the file for potential issues.You could even introduce your own debugging function as wrapper to the error_log or file_put_contents functions and check inside of this function, if the “debug mode” is active. Separation of concerns: Logging debugging information to a file keeps the application code free of debugging output.This has some advantages, but some other drawbacks: Pros: Instead of a direct output on the screen, you could write the debugging output into a file. error_log, file_put_contents – logging to a file It’s easy to miss some lines which then end up on a live website.Ģ. Needs cleanup: Even if you only use this technique while developing locally, you always have to remember this code, before you deploy the code or commit and push it into version control.Not only does this look like an error, it was also be a security issue, when the content of the data you debug should not be visible. Insecure: When you use this technique on a live website, the output is visible to any visitor.This means that your layout/design gets distorted. Intrusive: When you output the variables, you do might do that while rendering a template.As the output is often rendered into an HTML document, you might have to wrap it in a tag for array/objects or you have to check them in the source code view. You only get the value of that one variable, but no “context”. Output limitations: The methods are rather simple.Quick insight: When you just want to output a value at a certain line, it’s easy to get the current value at that line. ![]() You don’t have to install anything to use them. For arrays and objects, you would use print_r or var_dump. With echo you can output a generic value like a string or number. echo, print_r, var_dump – the quick but ugly wayĪnyone who ever developed something in PHP has used one of the “output functions”. I might write about that in an upcoming blog post, but today, I want to focus on different methods to debug code in PHP. This week, I was asked for help setting up Xdebug with PhpStorm on a Linux laptop in combination with Docker. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |