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.
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!
Next chapter: Common errors >>
Previous chapter: Error types
Home: Table of Contents
Copyright ©2015 Paul Hudson. Follow me: @twostraws.