如何解决“非静态方法xxx:xxx()在PHP 5.4中不应静态调用? [英] How can I solve "Non-static method xxx:xxx() should not be called statically in PHP 5.4?

查看:188
本文介绍了如何解决“非静态方法xxx:xxx()在PHP 5.4中不应静态调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前使用的是PHP大型平台.

Currently using a large platform in PHP.

其托管的服务器最近已升级到PHP 5.4.

The server it's hosted on has recently been upgraded to PHP 5.4.

从那时起,我收到了许多错误消息,例如:

Since, I've received many error messages like:

[2012年5月26日星期六19:04:41] [错误] PHP严格标准:非静态方法Config :: getData()不应被静态调用,假设$ this来自/xxx/Config.inc中的不兼容上下文.php行35

[Sat May 26 19:04:41 2012] [error] PHP Strict Standards: Non-static method Config::getData() should not be called statically, assuming $this from incompatible context in /xxx/Config.inc.php on line 35

示例方法定义为(请注意缺少"static"关键字):

The example method is defined as (note the lack of 'static' keyword):

function &getData() {
            $configData =& Registry::get('configData', true, null);

    if ($configData === null) {
        // Load configuration data only once per request, implicitly
        // sets config data by ref in the registry.
        $configData = Config::reloadData();
    }

    return $configData;
}

这以前没有引起问题,我认为错误消息(这会导致应用程序崩溃)可能与最近升级到PHP5.4有关.

This has no caused a problem before, and I assume the error messages (which cause the application to crash) may be related to the recent upgrade to PHP5.4.

是否可以修改PHP设置以忽略"缺少静态关键字?

Is there a PHP setting I can modify to 'ignore' the lack of static keyword?

推荐答案

您可以从error_reporting()中删除E_STRICT,也可以将其静态化(如果需要静态调用).据我所知,没有一种(严格的)方法可以使方法既可以作为静态方法也可以作为非静态方法来调用.另外,更令人讨厌的是,不能有两个同名的方法,一个是静态的,另一个是非静态的.

You can either remove E_STRICT from error_reporting(), or you can simply make your method static, if you need to call it statically. As far as I know, there is no (strict) way to have a method that can be invoked both as static and non-static method. Also, which is more annoying, you cannot have two methods with the same name, one being static and the other non-static.

这篇关于如何解决“非静态方法xxx:xxx()在PHP 5.4中不应静态调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆