Re: RFC: Comparable interface
| From: | Stas Malyshev | Date: | Thu, 30 Sep 2010 20:28:49 +0000 |
| Subject: | Re: RFC: Comparable interface | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49829@lists.php.net to get a copy of this message | ||
Hi!
The RFC is at http://wiki.php.net/rfc/comparable, and the patch at http://www.adamharvey.name/patches/comparable.diff.txt. Any and all feedback welcome, particularly since I'm still learning my way around the innards of the Zend Engine, and it's entirely possible (indeed, likely) that I've overlooked something obvious.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? 2. How it is ensured that if $a < $b then $b > $a? 3. Would sorting work with it? 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. 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. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227