Re: ArrayAccess and array_key_exists function

From: Date: Mon, 19 Feb 2024 13:21:19 +0000
Subject: Re: ArrayAccess and array_key_exists function
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-122436@lists.php.net to get a copy of this message
On Monday, 19 February 2024 at 12:32, Ondřej Mirtes <ondrej@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 Hello Ondřej, I'm been working on overhaulling the semantics of "container" objects as ArrayAccess can have some peculiar behaviour, but this is because the underlying engine handlers are also complex. I think this change makes sense and will keep it in mind/add it to my RFC. Best regards, Gina P. Banyard

« previous php.internals (#122436) next »