# SPL ArrayAccess offsetExists default behavior

- Thread: https://externals.io/message/42606
- Original archive: https://news-web.php.net/php.internals/42606
- Started by Mark van der Velden on 2009-01-13T15:43:58+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #42606 — Mark van der Velden — 2009-01-13T15:43:58+00:00

URL: https://externals.io/message/42606#42606

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 ?


- Mark

---

## #42608 — Etienne Kneuss — 2009-01-13T15:58:07+00:00

URL: https://externals.io/message/42606#42608 · In reply to: #42606

Hello,


> 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
>
> --
> 
> 
>
>
>
>



-- 
Etienne Kneuss
http://www.colder.ch

Men never do evil so completely and cheerfully as
when they do it from a religious conviction.
-- Pascal

---

## #42825 — Lukas Kahwe Smith — 2009-01-25T15:29:17+00:00

URL: https://externals.io/message/42606#42825 · In reply to: #42608

> Hello,
>
> On Tue, Jan 13, 2009 at 4:43 PM, Mark van der Velden <mark@dynom.nl>  
> wrote:
> > […]
>
> 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.


Hmm, maybe still worthwhile to classify it as a bug fix? :)

regards,
Lukas Kahwe Smith
mls@pooteeweet.org
