在 PHP 5.4 中禁用严格标准

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9983286/
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 08:01:26  来源:igfitidea点击:

Disabling Strict Standards in PHP 5.4

phperror-handling

提问by icomrade

I'm currently running a site on php 5.4, prior to this I was running my site on 5.3.8. Unfortunately, php 5.4 combines E_ALLand E_STRICT, which means that my previous setting for error_reportingdoes not work now. My previous value was E_ALL & ~E_NOTICE & ~E_STRICTShould I just enable values one at a time?

我目前在 php 5.4 上运行一个站点,在此之前我在 5.3.8 上运行我的站点。不幸的是,php 5.4 结合了E_ALLE_STRICT,这意味着我之前的设置error_reporting现在不起作用。我以前的值是E_ALL & ~E_NOTICE & ~E_STRICT我应该一次只启用一个值吗?

I have far too many errors and the files contain too much code for me to fix.

我有太多错误,而且文件包含太多代码需要我修复。

回答by David Stockton

As the commenters have stated the bestoption is to fix the errors, but with limited time or knowledge, that's not always possible. In your php.ini change

正如评论者所说,最好的选择是修复错误,但在时间或知识有限的情况下,这并不总是可能的。在你的 php.ini 更改

error_reporting = E_ALL

to

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

If you don't have access to the php.ini, you can potentially put this in your .htaccess file:

如果您无权访问 php.ini,则可以将其放入 .htaccess 文件中:

php_value error_reporting 30711

This is the E_ALL value (32767) and the removing the E_STRICT (2048) and E_NOTICE (8) values.

这是 E_ALL 值 (32767) 以及删除 E_STRICT (2048) 和 E_NOTICE (8) 值。

If you don't have access to the .htaccess file or it's not enabled, you'll probably need to put this at the top of the PHP section of any script that gets loaded from a browser call:

如果您无权访问 .htaccess 文件或未启用它,您可能需要将它放在从浏览器调用加载的任何脚本的 PHP 部分的顶部:

error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);

One of those should help you be able to use the software. The notices and strict stuff are indicators of problems or potential problems though and you may find some of the code is not working correctly in PHP 5.4.

其中之一应该可以帮助您使用该软件。通知和严格的内容是问题或潜在问题的指标,您可能会发现某些代码在 PHP 5.4 中无法正常工作。

回答by Taras

.htaccess php_value is working only if you use PHP Server API as module of Web server Apache. Use IfModule syntax:

.htaccess php_value 仅在您使用 PHP Server API 作为 Web 服务器 Apache 的模块时才有效。使用 IfModule 语法:

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
    php_value error_reporting 30711
</IfModule>

If you use PHP Server API CGI/FastCGI use

如果你使用 PHP Server API CGI/FastCGI 使用

ini_set('error_reporting', 30711);

or

或者

error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);

in your PHP code, or PHP configuration files .user.ini | php.ini modification:

在您的 PHP 代码或 PHP 配置文件中 .user.ini | php.ini 修改:

error_reporting = E_ALL & ~E_STRICT & ~E_NOTICE

on your virtual host, server level.

在您的虚拟主机,服务器级别。

回答by Guzik

It worked for me, when I set error_reporting in two places at same time

somewhere in PHP code

当我

在 PHP 代码的某处同时在两个地方设置 error_reporting 时,它对我有用

ini_set('error_reporting', 30711);


and in .htaccess file


并在 .htaccess 文件中

php_value error_reporting 30711

回答by ux.engineer

If you would need to disable E_DEPRACATED also, use:

如果您还需要禁用 E_DERACATED,请使用:

php_value error_reporting 22527

In my case CMS Made Simple was complaining "E_STRICT is enabled in the error_reporting" as well as "E_DEPRECATED is enabled". Adding that one line to .htaccess solved both misconfigurations.

在我的情况下,CMS Made Simple 抱怨“在 error_reporting 中启用了 E_STRICT”以及“启用了 E_DEPRECATED”。将这一行添加到 .htaccess 解决了两个错误配置。

回答by Moon

Heads up, you might need to restart LAMP, Apache or whatever your using to make this take affect. Racked our brains for a while on this one, seemed to make no affect until services were restarted, presumably because the website was caching.

注意,您可能需要重新启动 LAMP、Apache 或任何您使用的工具才能使其生效。在这个问题上绞尽脑汁,在服务重新启动之前似乎没有任何影响,大概是因为网站正在缓存。