# Iterable object can't return object in key

- Thread: https://externals.io/message/46955
- Original archive: https://news-web.php.net/php.internals/46955
- Started by mathieu.suen on 2010-02-08T14:31:12+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

---

## #46955 — mathieu.suen — 2010-02-08T14:31:12+00:00

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

Hi,

Whenever you implement the Iterator interface the key method should only 
return a scalar.
Is there any particular reason for this restriction.
IMHO I don't see any.
I also don't see why you can't index an array with object but it smells 
something going wrong underneath.

Thanks

- Mathieu Suen

---

## #46956 — Etienne Kneuss — 2010-02-08T15:29:45+00:00

URL: https://externals.io/message/46955#46956 · In reply to: #46955

Hello,


> Hi,
>
> Whenever you implement the Iterator interface the key method should only
> return a scalar.
> Is there any particular reason for this restriction.
> IMHO I don't see any.

The iterator interface was implemented on top of an API that
explicitly requested integers/strings as keys. It hasn't been changed
since.

> I also don't see why you can't index an array with object but it smells
> something going wrong underneath.

Historic reasons. Nothing would technically prevent objects from being
accepted as keys. Also, note that the SPLObjectStorage class can be
used for that task precisely. It is designed to work as an Object
Map/Set.

>
> Thanks
>
> - Mathieu Suen
>
> --
> 
> 
>
>



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