Want to see your php errors?

PHP Error Settings

Are you having trouble testing and debugging your code? Would you like to see your php error messages in your browser? Here's how you can turn on php errors; add the following code to the top of your php script.

ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);

If you also want to see parse errors you will also need edit the php.ini file and restart apache. Here is the change you need to make.

display_errors = on

One last thought: You may want to have a config option such as $debug="yes" that not only turns on displaying error messages, but any other debugging data you may work into your code. For example you could do something like: 

if($config['debug']=="yes") {	error_reporting(E_ALL & ~E_NOTICE);	ini_set("display_errors", 1);}

and then else where in your code something like this:

if($config['debug']=="yes") {     echo "test output of some function";}

You will notice that I personally don't normally display the startup errors.


Tags: Apache, Linux, PHP