gpt4 book ai didi

PHP 7.4 警告 : Creating default object from empty value

转载 作者:行者123 更新时间:2023-12-04 10:20:30 25 4
gpt4 key购买 nike

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

Warning: Creating default object from empty value in libraries/cegcore2/libs/helper.php on line 22


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;
}
}
}

}

最佳答案

问题是假设 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;
}
}
}

关于PHP 7.4 警告 : Creating default object from empty value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60885432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com