Array reference always succeeds

php -r 'var_dump($a["foo"]);var_dump(&$a["foo"]);var_dump($a);'

PHP Notice:  Undefined variable: a in Command line code on line 1
NULL
&NULL
array(1) {
  ["foo"]=>
  NULL
}

The WTF here is the lack of a second notice and the fact that the array changed. There is logic in this, of course, but it's weird to the extreme. You can even add a &$a['foo']['bar'] to this and despite &$a['foo'] not being an array it will still succeed.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options