Re: [RFC] Modify resolution order of count_elements handler
| From: | Marcus Boerger | Date: | Sun, 06 Jul 2008 11:01:14 +0000 |
| Subject: | Re: [RFC] Modify resolution order of count_elements handler | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-38788@lists.php.net to get a copy of this message | ||
Hello Etienne,
Wednesday, July 2, 2008, 1:57:06 PM, you wrote:
> Hi,
> I'd like to fix the resolution order of Countable::count() vs
> count_elements handler.
> Currently, things are done like this:
> 1) check if the object implements countable, if so, call it's method
> 2) if not, check if count_elements handler is defined, if so, use it.
> This is a problematic order of resolution, and I'd like to inverse it.
> Why? Because :
> 1) it is inconsistent with other handlers
> 2) it makes it impossible to be userland friendly while saving a
> method call when it's possible.
Sounds good to me and while you're at it. You can get rid of HAVE_SPL
checks as SPL is always present now.
> Currently, there are 3 possibilities:
> 1) the internal class doesn't use count_elements handler
->> No problem with the change
> 2) the internal class uses only the handler
->> It's not userland friendly, the change won't help, so it needs to
> be fixed anyway
> 3) both the handler and the method are used
->> the handler was never called directly, such classes will need a fix
> after that resolution order change.
Sounds like the interface_gets_implemented handler of the interface should
check that the count_elements handler is not set or is already set to the
same value anyway and throw an exception/issue an error otherwise.
> Userland classes are not affected.
> I can and will take care of every problems occuring in classes in
> php-src (2 or 3, mostly SPL).
> Patches and details:
> http://wiki.php.net/rfc/array_count_handlers
> Regards
> --
> Etienne Kneuss
> http://www.colder.ch
> Men never do evil so completely and cheerfully as
> when they do it from a religious conviction.
> -- Pascal
Best regards,
Marcus