Re: Iterable object can't return object in key
| From: | Etienne Kneuss | Date: | Mon, 08 Feb 2010 15:29:45 +0000 |
| Subject: | Re: Iterable object can't return object in key | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-46956@lists.php.net to get a copy of this message | ||
Hello,
On Mon, Feb 8, 2010 at 3:31 PM, mathieu.suen <mathieu.suen@easyflirt.com> wrote:
> 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
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Etienne Kneuss
http://www.colder.ch