php 非静态方法 PEAR::isError() 不应静态调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19248503/
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
Non-static method PEAR::isError() should not be called statically
提问by a coder
After upgrading from RHEL 5x to CentOS 6x, I started seeing these errors in my httpd log:
从 RHEL 5x 升级到 CentOS 6x 后,我开始在 httpd 日志中看到这些错误:
PHP Strict Standards: Non-static method PEAR::isError() should not be called statically in /web/sites/blah/somescript.php on line 33
PHP 严格标准:非静态方法 PEAR::isError() 不应在第 33 行的 /web/sites/blah/somescript.php 中静态调用
I saw similar errors for MDB2. More on that in a sec.
我看到了 MDB2 的类似错误。稍后会详细介绍。
somescript.php:
somescript.php:
32 $mdb2_dbx = MDB2::factory($dsn_mdb2, $mdb2_options);
33 if (PEAR::isError($mdb2_dbx))
34 {
35 $err = '<p>Cannot connect to database: ' . $mdb2_dbx->getMessage();
36 errorHandler($err);
37 }
The first thing I did was edit /etc/php.ini
and add & ~E_STRICT
to error reporting. Restarted httpd to load the new config. Still getting these error messages.
我做的第一件事是编辑/etc/php.ini
并添加& ~E_STRICT
到错误报告中。重新启动 httpd 以加载新配置。仍然收到这些错误消息。
Others mentioned the same problem with MDB2, so I updated these packages to the beta releases. This seemed to address MDB2 errors, but I'm still getting the PEAR error messages in httpd log file.
其他人提到了与 MDB2 相同的问题,因此我将这些软件包更新为beta 版本。这似乎解决了 MDB2 错误,但我仍然在 httpd 日志文件中收到 PEAR 错误消息。
System info:
系统信息:
# pear list
PEAR 1.9.4 stable
MDB2 2.5.0b5 beta
MDB2_Driver_mysql 1.5.0b4 beta
MDB2_Driver_mysqli 1.5.0b4 beta
# php --version
PHP 5.4.20 (cli) (built: Sep 18 2013 19:55:33)
# cat /etc/centos-release
CentOS release 6.4 (Final)
# apachectl -v
Server version: Apache/2.2.15 (Unix)
Question
题
Is there a different way of invoking PEAR::isError()
that will not produce errors?
是否有不同的调用方式PEAR::isError()
不会产生错误?
采纳答案by johannes
No there isn't. PEAR::isError
is legacy from PHP 4 times.
不,没有。PEAR::isError
是 PHP 4 次的遗产。
If changing the error level in php.ini
is not enough you should check
如果更改错误级别php.ini
还不够,您应该检查
- whether there is another php.ini file being loaded (check phpinfo() output via Apache)
- some script sets the error level.
- 是否正在加载另一个 php.ini 文件(通过 Apache 检查 phpinfo() 输出)
- 一些脚本设置错误级别。
If all that doesn't help, set an appropriate level using the error_level()
function at runtime, or if nothing else helps, suppress the errors using the @
operator. Using @
should be avoided as it is relatively "slow" (error reporting is slow anyways ...) and it might hide other errors.
如果所有这些都没有帮助,请error_level()
在运行时使用该函数设置适当的级别,或者如果没有其他帮助,请使用@
运算符抑制错误。@
应该避免使用,因为它相对“慢”(错误报告无论如何都很慢......)并且它可能隐藏其他错误。
Long-term suggestion would be to use more modern libraries.
长期建议是使用更现代的图书馆。
回答by Winfield Trail
I'm afraid @johannes is incorrect - this is very doable. Simply substitute this in your recipe:
恐怕@johannes 是不正确的 - 这是非常可行的。只需在您的食谱中替换它:
if ((new PEAR)->isError($mdb2_dbx)) {
// Victory! Er, I mean, Error!
...
}
回答by Ulrich Christensen
It may be worth noting that that calling PEAR::isError($obj)
with one argument is equivalent to is_a($obj, 'PEAR_Error')
, if you're updating your own code. I know it is not best practice to "unwrap" a library method like that, but it is basically just an "instance of" check.
可能值得注意的PEAR::isError($obj)
是is_a($obj, 'PEAR_Error')
,如果您要更新自己的代码,则使用一个参数进行调用等效于。我知道“解开”这样的库方法不是最佳实践,但它基本上只是一个“实例”检查。