# ArrayAccess: Constant numeric string offsets become integers

- Thread: https://externals.io/message/99819
- Original archive: https://news-web.php.net/php.internals/99819
- Started by Rudi Theunissen on 2017-07-07T23:30:55+00:00
- Messages: 2
- 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

---

## #99819 — Rudi Theunissen — 2017-07-07T23:30:55+00:00

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

Bug:  https://bugs.php.net/bug.php?id=63217
PR:   https://github.com/php/php-src/pull/2607
Demo: https://3v4l.org/dagUP

I've heard mixed responses to this bug and the approach to fix it (or
whether we should at all). The two common opinions are that ArrayAccess
should behave exactly like an array, and the other is that it's up to the
implementer to handle the offsets.

I would like to propose that the aim of ArrayAccess is not to emulate the
*behaviour* of an array, but instead only use its access *syntax*. The way
an array handles numeric string keys, floats, booleans etc is specific to
how an array works, and should not be forced on objects that implement
ArrayAccess.

In the demo linked above, you'll notice that ArrayAccess already allows any
key type, but becomes inconsistent when a constant numeric string is used.
Notice that the HHVM result shows the expected behaviour.

We should either go full array behaviour, or full array syntax only. The
numeric string optimisation that causes this bug is broken and should
either be fixed or removed entirely.

An important note is that *this does not affect arrays or object properties
at all* - only ArrayAccess.

---

## #99820 — Sara Golemon — 2017-07-08T04:21:21+00:00

URL: https://externals.io/message/99819#99820 · In reply to: #99819

> Bug:  https://bugs.php.net/bug.php?id=63217
> PR:   https://github.com/php/php-src/pull/2607
> Demo: https://3v4l.org/dagUP
>
> We should either go full array behaviour, or full array syntax only. The
> numeric string optimisation that causes this bug is broken and should
> either be fixed or removed entirely.
>
Agreed.  offsetGet() et al should either normalize to keyish values,
or do no normalization at all.  The current PHP behavior is a
half-measure and incorrect by any measure.  I like HHVM's behavior
here as it gives more power to the script dev.

-Sara
