Set PHP Error Reporting Into The PHP File

In This Article

On PHP Error Reporting, first, you have to know about What is error reporting in PHP and how we enable it. Here is the list of the major part of error reporting in PHP which we talked about in this tutorial,

  • What is PHP error reporting?
  • About PHP error reporting on and off.

What is PHP Error Reporting?

Error reporting is an inbuilt feature of PHP and used to show all errors, notices, and warnings of the PHP file at the time of execution.

PHP has a main configuration file (PHP.ini) which we use to enable error reporting and also used for turn on necessary extensions.

Now we check if we do not have any access to the php.ini configuration file then how can we turn on the error reporting.

Also Read: Complete Guide PHP Error Log

About PHP Error Reporting On And Off

Turn On PHP Error Reporting

Below source code shows all errors, warnings, and notices of the PHP program.

<?php

//turn the display_errors setting to on

ini_set(‘display_errors’, 1);

ini_set(‘display_startup_errors’, 1);

// Report all PHP errors

error_reporting(E_ALL);

?>

The ini_set function will try to override the PHP configuration file source code.

Turn Off PHP Error Reporting

Below source code is used for off all the type of PHP errors from the execution.

<?php

// Turn off all error reporting

error_reporting(0);

?>

If user wants to turn on or off specific error reporting,

<?php

// Turn off all error reporting

error_reporting(0);

// Report simple running errors

error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Report all errors except E_NOTICE

error_reporting(E_ALL & ~E_NOTICE);

// Report all PHP errors

error_reporting(E_ALL);

// Report all PHP errors

error_reporting(-1);

// Same as error_reporting(E_ALL);

ini_set(‘error_reporting’, E_ALL);

?>

Here is the complete explanations of error reporting in PHP. Please let me know if you got any issue.

To know more you can check official site https://www.php.net/manual/en/.

Also Check:

Happy Coding..!

Originally Published on: Set PHP Error Reporting Into The PHP File — PHPCODER.TECH

I am a web application developer. FB Community: @mrpandatech, Twitter: @phpcodertech My PHP problem-solving site http://phpcoder.tech