Open In App

How do I get PHP errors to display?

There are four ways to display errors in PHP which are listed below: 

Example: To display errors in PHP the fastest and easiest way is by adding the following lines to your code.  



ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL); 

These two directives does not display parse errors.
Program 1:  




<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
 
include("gfg.php");
?>

Output: 



A warning will be shown- No such directory or file found in (location of file)
with the specified line of error.

To display errors including parse errors following changes must be made at php.ini and restart php-fpm, apche2  

display_errors = on

Program 2:  




<?php
 
// Display number 0 to 5
for($i = 0; $i <= 5 $i++) // Semicolon after $i<=5 is missing
{
echo $i;
}
?>

Output: 

The above directives will display any PHP errors encountered when loading the website on the browser. The display-errors should be disabled when the site is live to prevent any security when not in the development environment. 

Article Tags :