On 25 June 2024 21:24:32 BST, Rob Landers <rob@bottled.codes> wrote:
>The only way you’d observe this (that I can think of) is by performing a 
>for-each loop over the array. 

There are many ways you can observe the difference between an absent key and a 
null value; here are just a handful off the top of my head: 

- array_key_exists() (that's literally its purpose!)
- array_keys()
- count() (if the array held "an infinite number of nulls", we should return 
infinity for every array!)
- json_encode()
- print_r(), var_dump(), var_export()
- extract()

It may be questionable to give meaning to the difference in some of these 
cases, but different it definitely is. 


> If we don't like it, we can always create an RFC to treat non-existent keys 
> as an error instead of a warning.

I believe that is the explicit intention or desire of those who raised it from 
Notice to Warning. It would certainly prevent some bugs where a typo leads to 
the wrong key being accessed.

Personally, I'd like to see a few use cases catered for first, like 
$counters[$key]++ and $groups[$key][] = $value; Perhaps by introducing some 
equivalent of Python's "defaultdict". Because I do agree that the current 
behaviour is useful sometimes (even if I disagree in how to describe it).


Regards,
Rowan Tommins
[IMSoP]

Reply via email to