Search code examples
phpstaticstandardsstrictnon-static

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


This is a question specific to a custom wrote CMS we have taken over. We moved servers and the PHP version changed from 5.3.8 to 5.4.1. Since then we can't get the CMS to work and are getting this error:

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

Line 71 says:

$settings = new Vox_Model_Setting(Vox_Model_Setting::getMapper()->findOne(array('module' => 'users')));

Can anyone advise what may be going wrong?

Thanks :)

edit: adding getMapper()

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

Solution

  • Just change your method type, add the static keyword and call as you are doing now.

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

    to

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