2

The apache error logs are filling up with this. I don't want to suppress all errors though, and understand I need to create an object explicitly somewhere but the syntax escapes me.

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

}
2
  • if(!empty(&$view->_vars)) $this->_vars = &$view->_vars; // <---- Line 22 Commented Mar 27, 2020 at 11:56
  • What have you tried to debug the problem? What does $view contain? What does $view->_vars contain? Commented Mar 27, 2020 at 12:00

1 Answer 1

2

The problem is that assuming view is null, you should not refer its items. You can do it like this:

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;
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.