简体   繁体   English

在 PHP 5.4 中禁用严格标准

[英]Disabling Strict Standards in PHP 5.4

I'm currently running a site on php 5.4, prior to this I was running my site on 5.3.8.我目前在 php 5.4 上运行一个站点,在此之前我在 5.3.8 上运行我的站点。 Unfortunately, php 5.4 combines E_ALL and E_STRICT , which means that my previous setting for error_reporting does not work now.不幸的是,php 5.4 结合了E_ALLE_STRICT ,这意味着我之前的error_reporting设置现在不起作用。 My previous value was E_ALL & ~E_NOTICE & ~E_STRICT Should I just enable values one at a time?我之前的值是E_ALL & ~E_NOTICE & ~E_STRICT我应该一次只启用一个值吗?

I have far too many errors and the files contain too much code for me to fix.我有太多错误,而且文件包含太多代码需要我修复。

As the commenters have stated the best option 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 中无法正常工作。

.htaccess php_value is working only if you use PHP Server API as module of Web server Apache. .htaccess php_value 仅在您使用 PHP Server API 作为 Web 服务器 Apache 的模块时才有效。 Use IfModule syntax:使用 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 代码或 PHP 配置文件中 .user.ini | php.ini modification: php.ini 修改:

error_reporting = E_ALL & ~E_STRICT & ~E_NOTICE

on your virtual host, server level.在您的虚拟主机,服务器级别。

It worked for me, when I set error_reporting in two places at same time当我同时在两个地方设置 error_reporting 时,它对我有用

somewhere in PHP code PHP 代码中的某处

ini_set('error_reporting', 30711);


and in .htaccess file并在 .htaccess 文件中

php_value error_reporting 30711

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".就我而言,CMS Made Simple 抱怨“在 error_reporting 中启用了 E_STRICT”以及“启用了 E_DEPRECATED”。 Adding that one line to .htaccess solved both misconfigurations.将这一行添加到 .htaccess 解决了两个错误配置。

Heads up, you might need to restart LAMP, Apache or whatever your using to make this take affect.注意,您可能需要重新启动 LAMP、Apache 或任何您使用的工具才能使其生效。 Racked our brains for a while on this one, seemed to make no affect until services were restarted, presumably because the website was caching.在这个问题上绞尽脑汁,在服务重新启动之前似乎没有任何影响,大概是因为网站正在缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM