Re: [RFC] Combined Comparison Operator

From: Date: Fri, 14 Feb 2014 10:41:15 +0000
Subject: Re: [RFC] Combined Comparison Operator
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-72588@lists.php.net to get a copy of this message
On 13/02/2014 04:58, Davey Shafik wrote:
Hey folks, Hello Davey :-),
Thanks for the proposal.
I've written up an RFC/Patch to gauge interest and get feedback on the addition of a combined comparison (aka: spaceship) operator. You can see the RFC at: https://wiki.php.net/rfc/combined-comparison-operator This adds a new operator "(expr) <=> (expr)" that returns 0 if both operands are equal, 1 if the left is greater, and -1 if the right is greater. It works with all types (just as well as <, <=, >=, > work) and is great for usort() callbacks for example. Am I the only one who think that <=> is already a Mathematical operator standing for the “equivalence”?
PHP already uses => as a key/value matching operator for pairs in an array, whereas in Math., it is the “implies” operator. Right, we may still introduce the ==> later. But I can't see <=> becoming <==> or even <===>. Moreover, as Jordi and others have suggested, a simple PHP function will do the job, and much better. A -1/0/1 result depends on the compared values and the interpretation of these latters: do we compare the number of pairs in an array, just the keys, just the values, do we also compare the type…? To much context for a single unambiguous operator. One or more dedicated functions (one per type maybe) is a more realistic way in my opinion. Thoughts? Cheers :-). -- Ivan Enderlin Developer of Hoa http://hoa-project.net/ PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) http://disc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/

« previous php.internals (#72588) next »