严格标准:不应该静态调用非静态方法,假设$this来自不兼容的上下文中


Strict Standards: Non-static method should not be called statically, assuming $this from incompatible context

这是一个特定于我们接管的自定义编写CMS的问题。我们移动了服务器,PHP版本从5.3.8更改为5.4.1。从那时起,我们无法让CMS工作,并得到这个错误:

Strict Standards: Non-static method Vox_Model_Setting::getMapper() should not be called statically, assuming $this from incompatible context in /var/www/vhosts/ds8760.dedicated.turbodns.co.uk/eera-bioenergy.com/application/modules/users/models/Role.php on line 71

第71行说:

$settings = new Vox_Model_Setting(Vox_Model_Setting::getMapper()->findOne(array('module' => 'users')));
谁能告诉我哪里出了问题?

谢谢:)

编辑:添加getMapper()

    public function getMapper()
{
   if (null === self::$__mapper) {
      self::setMapper(new Vox_Model_Setting_Mapper());
   }
   return self::$__mapper;     
}

只需更改方法类型,添加static关键字并像现在一样调用。

public function getMapper() {
 if (null === self::$__mapper) 
 { 
  self::setMapper(new Vox_Model_Setting_Mapper());
 } 
 return self::$__mapper;    
}

public static function getMapper() { # see extra static keyword
 if (null === self::$__mapper) 
 { 
  self::setMapper(new Vox_Model_Setting_Mapper());
 } 
 return self::$__mapper;    
}

PHP 5.4默认激活了Strict Standards通知,在5.3中默认关闭了这些通知,并且可能被忽略了(因为大多数ppl. PHP。倾向于这样做,尽管这是一种不好的做法)。

要快速解决问题,请关闭它们(您可以使用此命令):

error_reporting(E_ALL ^ E_STRICT);

或者在htaccess中:

php_value error_reporting 30711

尽管如此,我还是强烈建议您一个一个地解决它们。可以通过在getMapper()函数中添加静态函数来修复您在这里指定的变量,但是这可能会影响脚本的其他部分(在这些部分中它可能是非静态调用的)。