Display_errors setting and page level error reporting settings

PHP script can be set to display error messages or not by changing display_error setting to On or Off. This setting is available in php.ini file which is a server level setting so not available for shared hosting accounts. But this can be overridden and local settings can be applied to display error or not. While developing scripts it is advisable to keep the display all type of error reporting to fix the bugs and to develop portability of the script. However we should suppress error messages in production servers as it will expose various details of script and database details to users.

IN our php.ini file there is a setting saying
display_errors = On
With this we can display all types of error and this can be changed to
display_errors=Off
This will not display any error message to visitors.

Local or script level settings

At the script level of any php page we can set the value like this which will change the php.ini setting , here is an example.
<?Php
$one = $two; 
?>
This will give this error message
 Notice: Undefined variable: two in J:\php_files\t\error\test.php on line 13
You may not like this error message to be displayed to your visitors so we can add error_reporting function like this.
<?Php
error_reporting(0);// With this no error reporting will be there
$one = $two; 
?>
No error message will be displayed with the above code.

Development environment

We should display all types of errors in a development environment.
error_reporting(E_ALL);
or
ini_set('display_errors', true);

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com




    Hire Php Developer

    03-07-2017

    Great tutorial. This tutorial was really helpful to known the error reporting in PHP. Thanks.

    Post your comments , suggestion , error , requirements etc here .




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2023 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer