Learn how to use PHP error_reporting Function
Here, On this Page, I'm Publishing Some information about error_reporting function in PHP including Definition, Syntax, Usage, Examples, Parameter Constants, Return Output and some related details associated with it. PHP error_reporting function simplifies our work of changing default behavior of "PHP Errors" directly from our scripts without editing the core "php.ini" configuration file. This function is a part of core "error_handling functions" in PHP which allows us to define our own error handling rules suiting our needs.
Definition and Usage
The error_reporting function allows us set levels of error (in PHP) to be displayed on screen for the particular duration (runtime) of our script.
Syntax of error_reporting Function
int error_reporting ([ int $level ] );
In the above syntax,
- First "int" indicates the data type of return value (function output),
- Second "int" indicates the data type of parameter that this function will accept including predefined parameter constants.
- $level is the parameter of error_reporting function which takes on either a bitmask or predefined named constants. As per the PHP official statement, named constants are suggested to ensure compatibility with future versions of PHP.
Latest Predefined Constants, Bitmasks and Description
Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
Run-time warnings (non-fatal errors). Execution of the script is not halted.
Compile-time parse errors. Parse errors should only be generated by the parser.
Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP.
Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP.
Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.
Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine.
User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error().
User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error().
User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error().
Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR.
Run-time notices. Enable this to receive warnings about code that will not work in future versions.
User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error().
All errors and warnings, as supported, except of level E_STRICT.
- Returns the old error_reporting level or the current level if no "level" parameter is given.
Example of error_reporting Function
<?php // Turn off all error reporting error_reporting(0); // Report simple running errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // Reporting E_NOTICE can be good too (to report uninitialized // variables or catch variable name misspellings ...) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // Report all errors except E_NOTICE // This is the default value set in php.ini error_reporting(E_ALL ^ E_NOTICE); // Report all PHP errors (see changelog) error_reporting(E_ALL); // Report all PHP errors error_reporting(-1); // Same as error_reporting(E_ALL); ini_set('error_reporting', E_ALL); ?>
- Passing in the value -1 as parameter will show every possible error, even when new levels and constants are added in future PHP versions.
More by this Author
How to Develop c++ programm that will try connecting to internet and will fetch data from it using Wininet Library (Devc++ IDE).
In this PHP tutorial, I'm Publishing some details about urlencode and rawurlencode functions of PHP which Includes syntax, examples, Character conversion table and much more...
Basic Knowledge and things that one should have before purchasing any laptop computer. Screen, Memory, Storage, Processor, Interface, Display, Graphics and Much More...