PHP and Error Reporting

PHP is capable of four levels of error reporting. PHP reports fatal errors, parser errors, warnings, and notices. You can set your desired level of error reporting in the php.ini file under the errors header. Or you may set the level of error reporting on the fly for your application. To set the error reporting level on the fly you can use the following function:

int error_reporting(int level);

The error_reporting() function takes an integer of the level of reporting you would like. Each of the four levels of errors has an integer value.

  • 1 – Fatal Errors

  • 2 – Warnings

  • 4 – Parser Errors

  • 8 – Notices

So to figure out the level of error reporting you would like, you simply add the values together. This is much like the permissions on a UNIX machine. For example, if you would like to report only fatal errors and warnings you would do the following:

error_reporting(3);

See how that works? Take a look at one more. Let’s say you wanted to report only notices, warnings, and fatal errors. You would use the following line:

error_reporting(11);

By the same token, if you supplied 0 as the value for the level then no errors would be reported. This is a handy function to use. While you are developing an application you can turn on your errors so you can debug problems. But when you put something into production you could simply set the error reporting level to 0 and have no fear that a user will see a big nasty error in the middle of a page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset