Re: How to detect classes with a count_elements handler in userland?
| From: | Nikita Popov | Date: | Thu, 17 Nov 2016 11:49:04 +0000 |
| Subject: | Re: How to detect classes with a count_elements handler in userland? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96946@lists.php.net to get a copy of this message | ||
On Thu, Nov 17, 2016 at 8:30 AM, Joe Watkins <pthreads@pthreads.org> wrote:
> Morning,
>
> Just to chime in ... can you split the PR into the RFC, and the new thing
> please.
>
> Just another question on how we could make objects that have
> count_elements (which is in object handlers) implement an interface on the
> class entry (which is detached from handlers) ?
>
> I'm sure it's doable, but it doesn't look very straight forward, some kind
> of hacking in instanceof maybe ... not sure ...
>
I don't think this needs any magic. We simply implement the interface by
convention. Just like you are supposed to implement Traversable if you're
implementing get_iterator. Similarly you should implement Countable if
you're using count_elements.
Nikita