Send a blank email to [email protected] to get a copy of this message
The behavior of dereferencing scalars as if they were arrays or strings
is arguable:
<?php
$foo = 42;
$foo['bar']; // => NULL
This happens without notice or warning, whereas the array dereferencing
of objects results in a fatal error:
<?php
$foo = new stdClass;
$foo['bar']; // Fatal error: Cannot use object of type stdClass as array
There are several bug reports and feature requests regarding this
behavior, the most interesting being #54556[1] and #64194[2]. The
former has a patch attached, for the latter there is a PR[3].
Would throwing a notice or a warning on array deferencing scalars
be acceptable for PHP 7.0, or does this need an RFC?
[1] <https://bugs.php.net/bug.php?id=54556>
[2] <https://bugs.php.net/bug.php?id=64194>
[3] <https://github.com/php/php-src/pull/1269>
--
Christoph M. Becker