Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 5.3 deprecation messages showing up as warnings

Tags:

php

I have a legacy app that requires register_globals and magic_quotes_gpc to be enabled. I have my error_reporting set to E_ALL & ~E_DEPRECATED because I still want to see any warnings.

When I run the PHP CLI I get the following

$ php -d "error_reporting=E_ALL & ~E_DEPRECATED" -v
PHP Warning:  Directive 'register_globals' is deprecated in PHP 5.3 and greater in Unknown on line 0
PHP Warning:  Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0
PHP 5.3.3 (cli) (built: Mar 30 2011 13:51:41)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans

Why is it showing the deprecation messages as warnings? Shouldn't they be in the E_DEPRECATED level?

It seems I have to not show warnings to get them to go away

$ php -d "error_reporting=E_ALL & ~E_WARNING" -v
PHP 5.3.3 (cli) (built: Mar 30 2011 13:51:41)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans

I could change my error_reporting to E_ALL & ~E_DEPRECATED & ~E_WARNING but then it wouldn't show warnings for my webapp. Any suggestions? Do I have to use a separate php.ini for the CLI?

like image 908
ejunker Avatar asked Sep 08 '11 18:09

ejunker


People also ask

How do I suppress E_deprecated error messages in PHP?

This post shows how to suppress E_DEPRECATED error messages. To show all errors other than E_DEPRECATED in the php.ini file, adjust the error_reporting setting as shown below. Note this should only be done for installs of PHP 5.3+. To suppress notices as well: You can either straight out set the error reporting level like so:

Why are there PHP notices and deprecated messages in the log?

There are PHP notices and deprecated messages filling up the /var/log/httpd/ssl_error_log file. This problem can be eliminated by updating the php .ini file. The advisory messages do not indicate a fatal error. To determine the location of your php .ini file, execute the following command:

How do I stop PHP from referring to deprecated functions?

If you receive errors regarding function deprecation, the following two methods can tell PHP to simply stop mentioning deprecated functions or coding: You can add the following line to your php5.ini file: error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE Or you may add the following line to a PHP file itself, inside existing or new <?php ?> tags:

How to show all errors other than E_deprecated in the error report?

To show all errors other than E_DEPRECATED in the php.ini file, adjust the error_reporting setting as shown below. Note this should only be done for installs of PHP 5.3+. To suppress notices as well:


1 Answers

Change error_reporting to E_ALL & ~E_DEPRECATED & ~E_WARNING.

Then, at the beginning of your code set:

error_reporting(E_ALL | E_STRICT);

Initial PHP checks have passed and now you have your complete error-reported environment. :)

like image 52
Denis Avatar answered Nov 01 '22 10:11

Denis