PHP 5.3 deprecation messages showing up as warnings
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开发者_如何学C-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?
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. :)
LMGTFY
The best REPLY
[2009-09-07 08:42 UTC] jani@php.net Yes. It's not E_DEPRECATED, it's E_WARNING and that's not gonna change.
[2010-03-23 14:26 UTC] kalle@php.net aks at esoft dot dk > If the documentation indeed says that, then report it as a separate issue instead of bumping an already closed report.
Looks like you have to accept the way of how it is behave.
The changes will only apply to v6
You might have some luck turning off the display of startup errors. The errors should still get logged to your error log, but they won't be displayed in your application's output.
It's considered best practice to not use either. They're E_WARNING
s because those are the type of errors that the developers have chosen to trigger (it's arbitrary to use one versus another at that level).
I highly recommend that you make sure those features are turned off in your configuration, or that if you can't avoid it, just turn those types of warnings off in the configuration. Otherwise, you risk it ruining an AJAX request. We all have to cope with it.
you could try registering your error handler with
set_error_handler("myFunc");
and myFunc is something like:
myFunc($errno,$errstr) {
return strpos($errstr,"register_globals")===false ? false : true;
}
so, if string "register_globals" is not found, func returns false and standard error handling starts, otherwise it just returns true and nothing happens.
精彩评论