Re: SPL ArrayAccess offsetExists default behavior
| From: | Etienne Kneuss | Date: | Tue, 13 Jan 2009 15:58:07 +0000 |
| Subject: | Re: SPL ArrayAccess offsetExists default behavior | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-42608@lists.php.net to get a copy of this message | ||
Hello,
On Tue, Jan 13, 2009 at 4:43 PM, Mark van der Velden <mark@dynom.nl> wrote:
> Hi list,
>
> The following doesn't strike me as consistent behavior:
>
> $a = new ArrayObject();
> $a["foobar"] = NULL;
>
> echo (int) isset( $a["foobar"] ); // Output: 1
>
>
> While it's technically correct, I find it confusing. The reason is probably
> because of a array_key_exists (or property_exists) check within
> offsetExists() that do not take return false on a NULL value, unlike
> isset().
>
> What say you ?
This is indeed a small inconsistency. The problem is that by its name,
offsetExists() should return true on those cases (similarly to
array_key_exists or property_exists). Since it is directly called
within isset(), isset() should return true as well. The problem is
that checking the value would cause a offsetGet() to be called, which
will be a BC break, so I'm not sure if it's worth changing.
Regards
>
>
> - Mark
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
--
Etienne Kneuss
http://www.colder.ch
Men never do evil so completely and cheerfully as
when they do it from a religious conviction.
-- Pascal