【问题标题】:Strict Standards: Non-static method should not be called statically, assuming $this from incompatible context严格标准:不应静态调用非静态方法,假设 $this 来自不兼容的上下文
【发布时间】:2015-08-09 18:46:47
【问题描述】:

这是一个特定于我们已接管的自定义编写的 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;     
}

【问题讨论】:

  • 检查你getMapper()函数类型。错误说它不是static,你称之为静态时尚。在调用其非静态方法之前,您必须创建一个 Vox_Model_Setting 类的 object
  • 嗨,这是 getMapper() public function getMapper() { if (null === self::$__mapper) { self::setMapper(new Vox_Model_Setting_Mapper()); } 返回自我::$__mapper; }

标签: php static standards strict non-static


【解决方案1】:

只需更改您的方法类型,添加 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;    
}

【讨论】:

    【解决方案2】:

    PHP 5.4 带有默认激活的严格标准通知,在 5.3 中默认关闭的通知可能被忽略(因为大多数人倾向于这样做,尽管这是一种不好的做法)。

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

    error_reporting(E_ALL ^ E_STRICT);

    或者在 htaccess 中:

    php_value error_reporting 30711

    不过,我还是强烈建议您一一修复它们。您在那里指定的那个可以通过向 getMapper() 函数添加静态来修复,但这可能会影响脚本的其他部分(可能会被非静态调用)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      • 2016-09-21
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多