Why there is no E_NOTICE error in the first call?

Viewed 140

I have a following code snippet:

 error_reporting(E_ALL | E_STRICT);

    function &getVal() {
       $data = [];

       return $data['hey'];
       //return $whatever; 
    }

    function getVal2() {
       $data = [];

       return $data['hey'];
    }

    var_dump(getVal());  // No E_NOTICE error is issued - why?
    var_dump(getVal2()); // E_NOTICE error is issued.

And the question is: Why there is no E_NOTICE error in the first call? The explanation is most likely that the variable $data['hey'] is created to return a reference. However, it still seems wrong not to issue an E_NOTICE error when $data['hey'] (or $whatever, ...) is not defined.

3 Answers
Related