Debugging a PHP script, you may want to alter the error-displaying sensitivity on a particular page and control what types of errors should be reported.
The solution is the PHP error reporting function error_reporting():
error_reporting(E_ALL); // everything
error_reporting(E_ERROR | E_PARSE); // only major problems
error_reporting(E_ALL & ~E_NOTICE); // everything but notices
As the parameters of the function, &, | and ~ are all bitwise operators to determine what kind of errors are to be reported. Be advised by the following explanation:
- | stands for ‘OR‘.
- & stands for ‘AND‘.
- ~ stands for ‘NOT‘.
Value |
Constant |
Description |
Catchable |
---|---|---|---|
1 |
E_ERROR |
Nonrecoverable error |
No |
2 |
Recoverable error |
Yes |
|
4 |
E_PARSE |
Parser error |
No |
8 |
E_NOTICE |
Possible error |
Yes |
16 |
Like E_ERROR but generated by the PHP core |
No |
|
32 |
Like E_WARNING but generated by the PHP core |
No |
|
64 |
Like E_ERROR but generated by the Zend Engine |
No |
|
128 |
Like E_WARNING but generated by the Zend Engine |
No |
|
256 |
Like E_ERROR but triggered by calling trigger_error( ) |
Yes |
|
512 |
Like E_WARNING but triggered by calling trigger_error( ) |
Yes |
|
1024 |
Like E_NOTICE but triggered by calling trigger_error( ) |
Yes |
|
2047 |
E_ALL |
Everything except E_STRICT |
N/A |
2048 |
E_STRICT |
Runtime notices in which PHP suggests changes to improve code quality (since PHP 5) |
N/A |