How to debug a PHP script

It could be useful sometimes to know what variables are defined at particular point of PHP script in order to have a better understanding of the code you are debugging. In contrast with C++, PHP has a magic function get_defined_vars ( void ) that  returns an array of all defined variables with their values so we can output all variable names with the following line of code:


To know where are this variables come from we can print the stack trace:


And, of course we can examine log files located on the web server in /var/log/nginx/ or /var/log/apache/ directories.

Leave a Reply

Your email address will not be published. Required fields are marked *