For what it's worth, I'm planning to update the RFC later today with
an updated SPL-less patch and the start of a Q&A section similar to
what we've had in the other RFCs. I'll send an e-mail when it's ready.

On 1 October 2010 04:28, Stas Malyshev <smalys...@sugarcrm.com> wrote:
> It is not clear from the RFC, if the engine encounters $a <= $b, what
> actually happens?
> E.g.:
> 1. Is only $a checked for Comparable or also $b?

Both $a and $b are checked.

> 2. How it is ensured that if $a < $b then $b > $a?

That's up to the userspace developer to get right when they're
implementing their compareTo method. I expect the manual would have a
dire warning about the possible consequences of not making them
equivalent.

> 3. Would sorting work with it?

Yes.

> 4. If both $a and $b are objects with different compare functions, how it is
> determined whose function is used? Note that operators like == are assumed
> to be commutative, and less/more operators are assumed to be commutative in
> pairs, like above.

The left operand wins, so $a.

> As a side note, if we have traits we might instead think of having
> Comparable trait or interface or both, which would declare having
> compareTo() standard feature (as Java does) without messing with the engine
> and overloading operators. Surely, it would be more verbose, but that might
> be a good thing.

I don't think that gains us an awful lot (it's no different to simply
having an interface or trait within a codebase requiring such a
function, which has been common practice in some of the systems I work
on anyway), but it'd be easy enough to add, obviously.

Adam

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to