php 如何消除php5严格标准错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12229113/
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
How to eliminate php5 Strict standards errors?
提问by qxlab
After upgrading my PHP to 5.4.3 (WAMP server 2.2), my web app made in CakePHP 1.3, is showing the following errors in my index:
将我的 PHP 升级到 5.4.3(WAMP 服务器 2.2)后,我在 CakePHP 1.3 中制作的 Web 应用程序在我的索引中显示以下错误:
Strict standards: Redefining already defined constructor for class Object in C:...\cake\cake\libs\object.php on line 63
Strict standards: Non-static method Configure::getInstance() should not be called statically in C:...\cake\cake\bootstrap.php on line 49
严格的标准:在 C:...\cake\cake\libs\object.php 第 63 行重新定义已定义的类 Object 的构造函数
严格标准:非静态方法 Configure::getInstance() 不应在 C:...\cake\cake\bootstrap.php 第 49 行静态调用
I've found that some people solve this problem by setting the error_reportingin php.ini to E_ALL & ~E_STRICT.
我发现有些人通过将error_reportingphp.ini设置为E_ALL & ~E_STRICT.
I did that in both php.ini files (C:\wamp\bin\php\php5.4.3 and C:\wamp\bin\apache\apache2.4.2\bin) present on my computer but it didn't solve the problem.
我在计算机上的两个 php.ini 文件(C:\wamp\bin\php\php5.4.3 和 C:\wamp\bin\apache\apache2.4.2\bin)中都这样做了,但它没有解决问题.
I also tried to put php_value error_reporting 6143in C:...\cake.htaccess but without success.
我也尝试放入php_value error_reporting 6143C:...\cake.htaccess 但没有成功。
Does anybody know how can I solve this? I can't upgrade my CakePHP because of firebird.
有谁知道我该如何解决这个问题?由于 firebird,我无法升级我的 CakePHP。
采纳答案by JvdBerg
One of the changes in php 5.4 is that E_STRICT is now part of E_ALL
php 5.4 的变化之一是 E_STRICT 现在是 E_ALL 的一部分
So, in your /cake/bootstrap.php you could remove the E_STRICT from your error reporting:
因此,在您的 /cake/bootstrap.php 中,您可以从错误报告中删除 E_STRICT:
error_reporting(E_ALL ^ E_STRICT);
and be compatible again with before 5.4 versions.
并再次兼容 5.4 之前的版本。
回答by Claudio Bredfeldt
Instead of modifying the cake core files, which sucks if you want to update your cake version, go into your Config/core.php file and look for the error handler configuration:
不要修改 cake 核心文件,如果你想更新你的 cake 版本,这很糟糕,进入你的 Config/core.php 文件并查找错误处理程序配置:
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
and replace 'level' with this:
并用这个替换“级别”:
...
'level' => E_ALL & ~E_STRICT & ~E_DEPRECATED,
...
回答by Ruut
Please replace
请更换
error_reporting = E_ALL
in your php.ini, with
在你的php.ini 中,
error_reporting = E_ALL & ~E_STRICT
For me
为了我
error_reporting(E_ALL ^ E_STRICT);
which is shown in the accepted answer to this question did not work and gave an Infinite loop detected in JErrorerror for my Joomla website.
这在这个问题的已接受答案中显示不起作用,并且在我的 Joomla 网站的JError错误中检测到了一个无限循环。
回答by Gaurang P
You are using newer php version. in php 5.4, E_STRICT is part of E_ALL
您正在使用较新的 php 版本。在 php 5.4 中,E_STRICT 是 E_ALL 的一部分
in cake 1.3, open file /cake/bootstrap.php and change the error_reporting like this
在 cake 1.3 中,打开文件 /cake/bootstrap.php 并像这样更改 error_reporting
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
回答by Serge S.
If you're fighting with PHP Strict warnings in cake console output, take a look into your app/config/core.php.
如果您在蛋糕控制台输出中遇到 PHP Strict 警告,请查看您的app/config/core.php.
In CakePhp 1.3 error_reporting(...)is overwritten by the 'log'option, so ensure you exclude E_STRICThere:
在 CakePhp 1.3error_reporting(...)中,该'log'选项被覆盖,因此请确保E_STRICT在此处排除:
/**
* CakePHP Log Level:
*
* In case of Production Mode CakePHP gives you the possibility to continue logging errors.
*
* The following parameters can be used:
* Boolean: Set true/false to activate/deactivate logging
* Configure::write('log', true);
*
* Integer: Use built-in PHP constants to set the error level (see error_reporting)
* Configure::write('log', E_ERROR | E_WARNING);
* Configure::write('log', E_ALL ^ E_NOTICE);
*/
Configure::write('log', E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
回答by KingRider
File bootstrap.php from folder (root)cake
从文件夹(根)cake 文件 bootstrap.php
if (!defined('E_ALL')) {
define('E_ALL', 8192);
}
File debugger.php from folder (root)cake\libs
文件夹(根)cake\libs 中的文件 debugger.php
error_reporting(E_ALL ^ ~E_STRICT ^ ~E_DEPRECATED);
回答by cori
Make sure you've updated the correct php.ini file - if you create a php file in your root directory with the following code
确保您已更新正确的 php.ini 文件 - 如果您使用以下代码在根目录中创建一个 php 文件
<?php
phpinfo();
?>
and load it in your web browser it will tell you which ini file is being used, in case you missed one.
并将其加载到您的网络浏览器中,它会告诉您正在使用哪个 ini 文件,以防您错过了。
It's also possible that an htaccess file is setting that value via the php_flag error_reportingvalue, which can also be set per directory.
htaccess 文件也可能通过该php_flag error_reporting值设置该值,该值也可以按目录设置。

