Three ways to debug php

0
341

Method 1 – error.log

For this to work you need to be coding in a linux environment with php, apache etc setup. This is the best way I have found and what I currently use to debug my applications/web pages.

open up a new terminal and type:
tail -f /var/log/apache2/error.log

This will give you a readout of the last few error messages. Refresh the page you are working on in a browser and it’ll give you the fault code and line number where you probably forgot a semi-colon.

Method 2 – display all errors

Add the following lines to the top of your script:
ini_set(‘display_errors’, ‘On’);
error_reporting(E_ALL);

This will display all errors in the browser. Make sure you take it out before deployment.

Method 3 – Var Dump

If something just isn’t working but you aren’t getting an error blow the script apart by throwing a var dump into the equation. The following line will dump all defined variables into the browser.
var_dump(get_defined_vars()); //var dump all

Hope these tips will save some headaches or at least shorten the duration of them.

LEAVE A REPLY

Please enter your comment!
Please enter your name here