How to Disable Notice Messages, Warning Messages In PHP

How to Disable Notice Messages, Warning Messages In PHP 1

How to Disable Notice Messages in PHP

To disable notice messages in PHP you can use one of two options. Edit your php.ini file to globally turn off notices or use error_reporting() in your PHP scripts. You can also use .htaccess with the php_value error_reportingdirective but that isn’t covered in this tutorial. You can find more information about PHP Error Reporting on php.net.

The php.ini Method

The php.ini method disables notices for every PHP script running on the webserver. Use this method to globally disable all notices.

1. Edit your php.ini file. In Linux, this could be in /etc/php5/apache2/ or /etc/. On Windows, it is wherever you defaulted your installation. Use phpinfo() in a PHP script on your webserver to locate the location.

2. Find error_reporting and add ~E_NOTICE to the end. You may have something there already. It should look similar to this:
error_reporting = E_ALL & ~E_NOTICE

3. Restart your webserver

The error_reporting Method

This method disables notices on a single PHP script.

1. Edit the PHP file that is throwing notice messages.

2. Add error_reporting(~E_NOTICE) to the top of the file or above where the error is being thrown. It should look like this:

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

How to Disable Warning Messages in PHP

To disable warning messages in PHP you can use one of two options. Edit your php.ini file to globally turn off warnings or use error_reporting() in your PHP scripts. You can also use .htaccess with the php_value error_reportingdirective but that isn’t covered in this tutorial. You can find more information about PHP Error Reporting on php.net.

The php.ini Method

The php.ini method disables warnings for every PHP script running on the webserver. Use this method to globally disable all warnings.

1. Edit your php.ini file. In Linux, this could be in /etc/php5/apache2/ or /etc/. On Windows, it is wherever you defaulted your installation. Use phpinfo() in a PHP script on your webserver to locate the location.

2. Find error_reporting and add ~E_WARNING to the end. You may have something there already. It should look similar to this:
error_reporting = E_ALL & ~E_WARNING

3. Restart your webserver

The error_reporting Method

This method disables warnings on a single PHP script.

1. Edit the PHP file that is throwing warning messages.

2. Add error_reporting(~E_WARNING) to the top of the file or above where the error is being thrown. It should look like this:

// Report all errors except E_WARNING
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_WARNING);

Leave a Reply

Your email address will not be published. Required fields are marked *