Hudzilla.org - the homepage of Paul Hudson
Contents > Writing PHP > Troubleshooting Wish List | Report Bug | About Me ]

19.12.2     Choosing what types of errors you see: error_reporting()

This is NOT the latest copy of this book; click here for the latest version.

int error_reporting ( [int level])

The first weapon you have against finding and solving errors is the PHP function error_reporting(). This allows you to pass in one of the error type constants just listed as error_reporting() 's only parameter, and force PHP to only output that kind of error. You can set this value in your php.ini file under error_reporting, but the error_reporting() function allows you to modify it at run-time.

You can use the bitwise operators to combine error types together in complicated ways, for example:

error_reporting(E_ERROR);
error_reporting(E_ALL);
error_reporting(E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR);
error_reporting(E_ALL & ~E_NOTICE);

The first line will show only standard E_ERROR error messages, the second will show all error messages, the third will show all error messages (E_ERROR, E_CORE_ERROR, and E_COMPILE_ERROR), and the last line will show all error messages except notices. The last option is usually the default, however I recommend you use E_ALL by itself, and have PHP show notices - these are often gremlin bugs waiting to happen.

Author's Note: Try and program using E_ALL error messages, because that will make PHP show notices. Notices are there to tell you that you are not doing things ideally, and so often provide good hints and tips to make your PHP faster, safer, and less buggy.





<< 19.12.1 Error types   19.12.3 Common errors >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is three plus five?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow