PHP 5.3 弃用消息显示为警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7353087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:32:56  来源:igfitidea点击:

PHP 5.3 deprecation messages showing up as warnings

php

提问by ejunker

I have a legacy app that requires register_globalsand magic_quotes_gpcto be enabled. I have my error_reportingset to E_ALL & ~E_DEPRECATEDbecause I still want to see any warnings.

我有需要使用旧版应用程序register_globalsmagic_quotes_gpc启用。我有我的error_reporting设置,E_ALL & ~E_DEPRECATED因为我仍然想看到任何警告。

When I run the PHP CLI I get the following

当我运行 PHP CLI 时,我得到以下信息

$ 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_DEPRECATEDlevel?

为什么将弃用消息显示为警告?他们不应该在一个E_DEPRECATED级别吗?

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_reportingto E_ALL & ~E_DEPRECATED & ~E_WARNINGbut then it wouldn't show warnings for my webapp. Any suggestions? Do I have to use a separate php.inifor the CLI?

我可以将我更改error_reporting为,E_ALL & ~E_DEPRECATED & ~E_WARNING但它不会显示我的 web 应用程序的警告。有什么建议?我是否必须php.ini为 CLI单独使用?

回答by Denis

Change error_reportingto E_ALL & ~E_DEPRECATED & ~E_WARNING.

更改error_reportingE_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. :)

初始 PHP 检查已通过,现在您拥有完整的错误报告环境。:)

回答by ajreal

LMGTFY

LMGTFY

The best REPLY

最好的回复

[2009-09-07 08:42 UTC] [email protected] Yes. It's not E_DEPRECATED, it's E_WARNING and that's not gonna change.

[2010-03-23 14:26 UTC] [email protected] 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.

[2009-09-07 08:42 UTC] [email protected] 是的。这不是 E_DEPRECATED,而是 E_WARNING,而且不会改变。

[2010-03-23 14:26 UTC] [email protected] aks at esoft dot dk > 如果文档确实这样说,那么将其作为单独的问题报告,而不是撞到已经关闭的报告。

Looks like you have to accept the way of how it is behave.
The changes will only apply to v6

看起来你必须接受它的行为方式。
更改仅适用于 v6

回答by Dustin Oprea

It's considered best practice to not use either. They're E_WARNINGs 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).

最好的做法是不使用它们。它们是E_WARNING因为这些是开发人员选择触发的错误类型(在该级别使用一种与另一种是任意的)。

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.

我强烈建议您确保在您的配置中关闭这些功能,或者如果您无法避免它,只需在配置中关闭这些类型的警告。否则,您可能会冒着破坏 AJAX 请求的风险。我们都必须应对它。

回答by Dustin Oprea

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.

您可能有幸关闭了启动错误显示。错误仍应记录到错误日志中,但不会显示在应用程序的输出中。

回答by Grenjek

you could try registering your error handler with

你可以尝试注册你的错误处理程序

set_error_handler("myFunc");

and myFunc is something like:

和 myFunc 是这样的:

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.

因此,如果未找到字符串“register_globals”,则 func 返回 false 并开始标准错误处理,否则它只返回 true 而什么也没有发生。