2017-02-22 38 views
0

我使用PHP 5.6以下的方法,它总是能正常工作PHP7覆盖魔术方法__get不工作了

public function __get($name){ 

      if(!empty($this->_dynamicFields[$name])){ 
       if(!empty($this->_dynamicData[$name])){ 
        return $this->_dynamicData[$name]; 
       }else{ 
        return null; 
       } 
      }else{ 
       return parent::__get($name); // That's where the error happens when an array is called in $name 
      } 
     } 

现在,我们升级了服务器PHP7,当一个脚本调用GET-方法有一个数组,我得到

$object->$attributes[0] 

classname.Array没有定义

任何想法的错误?

+1

https://wiki.php.net/rfc/uniform_variable_syntax –

回答

0

这是由于PHP7中的Changes to the handling of indirect variables, properties, and methods,它打破了向后兼容性(另请参阅Uniform Variable Syntax)。

具体来说,在PHP5您的通话这样解释:

$object->$attributes[0] === $object->{$attributes[0]} 

然而,在PHP7您的通话这样解释:

$object->$attributes[0] === ($object->$attributes)[0] 

如果您修改代码以明确$object->{$attributes[0]}你应该看到它再次按预期工作。