The error_reporting command specifies which errors are reported to the programmer.
Here are various ways to use error_reporting:
<%?php
// Disable all error reporting
error_reporting(0);
// Simple execution errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Communicating E_NOTICE can also be beneficial, as it helps report uninitialized variables or catch errors in variable names.
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value in php.ini
error_reporting(E_ALL ^ E_NOTICE);
// Reports all PHP errors (bit value 63 can be used in PHP 3).
error_reporting(E_ALL);
// Identical to error_reporting(E_ALL);
ini_set(‘error_reporting’, E_ALL);
?>
You can find all the information about error_reporting on the page https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
We provide an example that, when executed, will yield information about the errors made.
<%?php
error_reporting(E_ALL);
// Variable assignment
$var_1 = $var_2;
$connection=Conect();
echo “Database connection established.<br>”;
?>
The information received about programming errors is:
Notice: Undefined variable: var_2 in /home/virtual/spacewww.com/var/www/html/test.php on line 10
Fatal error: Call to undefined function: conect() in /home/virtual/specewww.com/var/www/html/test2.php on line 12
If the error_reporting(E_ALL) statement hadn’t been included, the code wouldn’t have been debugged correctly.