Notice on non existing array key (on a boolean)
| From: | Nicolai Scheer | Date: | Tue, 25 Aug 2015 13:35:46 +0000 |
| Subject: | Notice on non existing array key (on a boolean) | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-87910@lists.php.net to get a copy of this message | ||
Hi all,
I'd expect the following code to throw a notice/warning:
$x = true;
$y = $x['foo'];
It executes completely silently.
$y is NULL afterwards, which is expected, since the right hand side of
the assignment is undefined.
If $x was an array (e.g. empty array), a E_NOTICE would be emitted.
Can anyone shed a light on this behaviour? If accessing non existing
array keys is worth a notice, shouldn't accessing an array index on a
non array be worth a notice as well (maybe even a warning)?
The other way round emits a warning (i.e. writing to an array key on a
non array):
$x = true;
$x['foo'] = 'bar';
Warning: Cannot use a scalar value as an array ...
Thanks for any insight,
greetings
Nico