How to enable or disable warnings and errors in PHP ?
In PHP, there are several types of errors and warnings that can occur during the execution of a script.
- Notice: This type of error occurs when a script encounters something that could indicate an error, but it is not critical. For example, using a variable that has not been defined yet.
- Warning: This type of error occurs when a script encounters something that could indicate an error, and it is more serious than a notice. For example, trying to open a file that does not exist.
- Fatal error: This type of error occurs when a script encounters a critical problem that prevents it from continuing to execute. For example, calling a function that has not been defined.
- Parse error: This type of error occurs when there is a syntax error in the script. For example, a missing semicolon or an unmatched parenthesis.
- Strict Standards : This type of error occurs when a script violates a strict coding standard. for example, using a deprecated function or not following the correct order of parameters.
By default, PHP will display all errors and warnings as they occur, but you can configure how these errors are handled using the error_reporting() function or the error_reporting directive in the php.ini file.
To enable or disable PHP errors, you can use the error_reporting() function.
To enable errors :
ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL);
To disable errors :
error_reporting(0); ini_set('display_errors', 0);
Alternatively, you can also configure these settings in your php.ini file by setting the error_reporting and display_errors directives.
error_reporting = E_ALL display_errors = On
or
error_reporting = E_ALL display_errors = Off