On Mon, Feb 19, 2024 at 1:35 PM Ondřej Mirtes <ond...@mirtes.cz> wrote:
>
> Hello everyone,
> I was recently surprised that ArrayAccess does not work with 
> array_key_exists() function.
>
> I am aware that ArrayAccess objects cannot be made to work with many array 
> functions because it does not provide a way to iterate over its keys, you can 
> only ask for and set specific previously known keys.
>
> But it could be made to work with array_key_exists(), because it already 
> works with isset() and there’s a direct method that could be used for this - 
> offsetExists().
>
> The use case I have in mind is that sometimes libraries that originally use 
> “array” in return types want to switch to objects and they make these objects 
> to implement ArrayAccess, for maximising the backward compatibility with the 
> old version. This mostly works, except for array_key_exists().
>
> Do you think we could add support for ArrayAccess objects in the 2nd 
> parameter of array_key_exists() function?
>
> Thank you.
>
> Ondřej Mirtes

I'd love to see all array_* functions accept iterators/objects instead
of only just arrays. Yes, I know the name says "array" but often we
just mean "do this operation on this thing that looks enough like an
array for now."

Robert Landers
Software Engineer
Utrecht NL

Reply via email to