Debugging PHP

Some of the php functions which could be used for debugging large chunks of php source code.

1. echo or print

simple way to debug the workflow.

echo "working till here";
exit;

2. var_dump

yet another simple way to dump the output to the browser and stops further execution

var_dump($variablename);

3. print_r

To debug arrays. This will print the array values recursively. Pre tags is used to have a good look of array

 echo "<pre>";
 print_r($arrayvariable);
 echo "</pre>";

4. error_reporting

this is not used for debugging. but some times script may throw out some error but is not displayed in the browser. in that case you could use as below as the first line of the php script

error_reporting(E_ALL)

To know more about this, check out your php.ini file

MediaWiki

This page has been accessed 1,481 times.

This page was last modified 19:52, 22 June 2006.