2

apache 错误日志填满了这个。我不想抑制所有错误,并且明白我需要在某处显式创建一个对象,但语法让我无法理解。

警告:从第 22 行的 library/cegcore2/libs/helper.php 中的空值创建默认对象

class Helper {
    use \G2\L\T\GetSet;

    var $view = null;
    var $_vars = array();
    var $data = array();
    var $params = array();

    function __construct(&$view = null, $config = []){
        $this->view = &$view;
        $this->_vars = &$view->_vars; // <---- Line 22
        $this->data = &$view->data;

        if(!empty($config)){
            foreach($config as $k => $v){
                $this->$k = $v;
            }
        }
    }

}
4

1 回答 1

2

问题是假设 view 是null,你不应该引用它的项目。你可以这样做:

function __construct(&$view = null, $config = []){
    $this->view = &$view;
    if ($view) {
        $this->_vars = $view->_vars; // <---- Line 22
        $this->data = $view->data;
    }

    if(!empty($config)){
        foreach($config as $k => $v){
            $this->$k = $v;
        }
    }
}
于 2020-03-27T12:07:32.187 回答