How do i enable display errors in php ini?

In PHP, we can decide whether to show an error to end-users or not. You can enable or disable error reporting in PHP with three approaches:

Approach 1: In the php.ini file, we can set the display_error parameter as on or off. The on means errors are displayed and off means no errors to display and report. To do so, open the “php.ini” file and search for the display_error parameter and change it to value on. Save the file. Restart all services of the webserver. Now it will display all the errors of the PHP script to the end-users. To disable the error reporting, set the display_error parameter to off. The off parametermeans it will not show any error to users.

Approach 2: The second approach to enable or disable error reporting is using the ini_set() function. It is an inbuilt function available in PHP to change the configuration settings available in the php.ini file. It takes two parameters, the first is the setting name you want to modify and the second is the value you want to assign.

If you want to change the value of the display_error parameter of the php.ini file

Enable the error reporting: It will enable error reporting.

ini_set("display_errors", "1") 

Disable the error reporting: It will disable the error reporting.

ini_set("display_errors", "0")

Example 1: In the code, we have enabled error reporting so it displays the error to the user. The “printname()” function is “undefined” because the name of the defined function is “printmyname()”.

PHP

   ini_set('display_errors','1');

  function printmyname()

  {

     echo "My name is GeeksforGeeks";

  }

  printname();

?>

Output:

Fatal error: Call to undefined function printname()

Example 2: The following code will turn off showing the error to users.

PHP

  ini_set('display_errors','0');

  function printmyname()

  {

     echo "My name is GeeksforGeeks";

  }

  printname();

?>

Output:

This page isn’t working. localhost is 
currently unable to handle this request.
HTTP ERROR 500

Approach 3: This approach can also be used to enable error reporting by using the error_reporting() function, which is a native PHP function that sets the error_reporting directive at runtime, i.e., it is used to sets which PHP errors are reported. This function also helps to set the different levels for the runtime (duration) of your script, as PHP contains various levels of error. This function accepts error names like E_ERROR, E_PARSE, E_WARNING, etc, as parameters, thereby allowing that specified errors to report. A few errors that occur in PHP are listed below:

  • E_PARSE: The compile-time error generated by the parser.
  • E_ERROR: Fatal runtime error-execution of script get’s halted.
  • E_WARNING: Non-fatal runtime error-execution of script get’s halted.
  • E_CORE_ERROR: Fatal errors occur during the initial startup of the script.
  • E_CORE_WARNING: Non-fatal errors occur during the initial startup of the script.
  • E_NOTICE: The script found something that might be an error.
  • E_ALL: Includes all errors and warnings.

Syntax:

error_reporting(error_names);

Parameter value:

  • error_names: It specifies the name of errors that will pass as an argument.

Note: The error_reporting() function also accepts integer 0 which turns off all error reporting and -1 turns on all error reporting.

Example 3: The below code represents how to use the error_reporting() function in a PHP script.

PHP

    error_reporting(E_ERROR | E_WARNING);

    error_reporting(E_ALL);

    error_reporting(E_ALL & ~E_PARSE);

    error_reporting(-1);

    error_reporting(0);

    echo "Sample error reporting code using error_reporting function";

?>

Output:

Sample error reporting code using error_reporting function

Why does PHP not show errors?

If you have set your PHP code to display errors and they are still not visible, you may need to make a change in your php. ini file. On Linux distributions, the file is usually located in /etc/php. ini folder.

How do I turn off display errors in PHP?

How to set display_errors to Off in my own file without using php.ini.
Go to your header.php or index.php..
add this code ini_set('display_errors', FALSE);.

How do I view PHP error logs?

Look for the entry Configuration File (php. Find the Error handling and logging section of the php. ini file. Make sure that both display_errors = On, display_startup_errors = On and log_errors = On are present and uncommented. Check the value of error_log - this tells you the location of the file errors are logged to.

How do I show PHP errors in Chrome?

How do I view PHP errors in Chrome ?.
E_ALL. error_reporting(E_ALL); By E_ALL error level, it will report all errors to the browser or chrome in your case specifically..
E_NOTICE. error_reporting(E_NOTICE); ... .
E_ERROR. error_reporting(E_ERROR ); ... .
E_WARNING. error_reporting(E_WARNING ); ... .
E_PARSE. error_reporting(E_PARSE );.