在 PHP 5.4 中禁用严格标准

2021-12-26 00:00:00 error-handling php

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

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_ALL and E_STRICT, which means that my previous setting for error_reporting does not work now. My previous value was E_ALL & ~E_NOTICE & ~E_STRICT Should I just enable values one at a time?

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

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

推荐答案

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

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

error_reporting = E_ALL

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

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

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

php_value error_reporting 30711

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

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

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

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:

error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);

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

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.

相关文章