On 13/09/2019 10:02, Robert Korulczyk wrote:
Why? If "assume $key2 exists as a key and is an integer" is so bad that PHP should halt 
my program, why should "assume $key1 exists and is an array"
be perfectly OK?
Warning is triggered by reading non-existing key, not assigning value to it. In 
`$foo[$key1][$key2] ??= 0` you never try to read non-existing key.


$foo[$key1] has to be read to determine if it's already an array, and if it has 
the key $key2, in the same way that in $foo[$key1]++, $foo[$key1] has to be 
read to determine if it's already an integer and what it's value is.

If we're talking about being strict, we shouldn't limit ourselves to what 
happens to give a warning today, we should be consistent in our reasoning. So 
if the reasoning is that accessing uninitialised array keys is dangerous, I 
should not be able to mention $foo[$key1][$key2] if $foo[$key1] doesn't yet 
exist.

Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to