RE: [PHP-DEV] [RFC] Combined Comparison Operator

From: Date: Thu, 13 Feb 2014 07:19:54 +0000
Subject: RE: [PHP-DEV] [RFC] Combined Comparison Operator
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Davey Shafik <[email protected]> wrote:
> 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.
>

Why not using $a - $b instead of $a <=> $b?


Simon J Welsh <[email protected]> wrote:
> The only real case I see for this is to save some boilerplate when 
> dealing with arrays. Strings have strcmp(), numbers have subtraction 
> And when you’re sorting objects, you probably want to be doing 
> the comparison on some string/numeric property.
>

Agreed! It would make more sense to write a comparison function for arrays/objects.


Best regards
Christian


Thread (20 messages)

« previous php.internals (#72546) next »