Re: [RFC] Reclassifying engine warnings
| From: | Rowan Tommins | Date: | Fri, 13 Sep 2019 09:21:43 +0000 |
| Subject: | Re: [RFC] Reclassifying engine warnings | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107066@lists.php.net to get a copy of this message | ||
On 13/09/2019 10:02, Robert Korulczyk wrote:
$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]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] ??= 0you never try to read non-existing key.