Christoph Becker wrote on 08/06/2015 22:11:
The behavior of dereferencing scalars as if they were arrays or strings
is arguable:
<?php
$foo = 42;
$foo['bar']; // => NULL
A few things to note here:
- accessing a *numeric* offset of a *string* is valid (selects a single
character)
- accessing a *string* offset of another string is interpreted as access
to character 0, with a Warning issued
- de-referencing this to two levels ($string['key']['key']) and then
attempting to write is a Fatal error
- as discussed elsewhere, coercing a NULL to an array seems perfectly
reasonable
- assigning to an offset of anything other than a string or array
results in a Warning and no change to the variable
While I agree that it's kind of surprising not to get even a Notice in
your example, I'm not 100% sure what the behaviour should be, given how
many different scenarios already have different behaviour. Maybe someone
needs to come up with a generalised rule?
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php