Re: [RFC] Combined Comparison Operator

From: Date: Thu, 13 Feb 2014 11:04:48 +0000
Subject: Re: [RFC] Combined Comparison Operator
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Wed, 2014-02-12 at 23:39 -0500, Davey Shafik wrote:

> function ($left, $right) {
>      if ($left[1] == $right[1]) {
>           return 0;
>      }
> 
>      if ($left[1] > $right[1]) {
>           return 1;
>      }
> 
>      if ($left[1] < $right[1]) {
>          return -1;
>      }
> }
> 
> or (as per the RFC):
> 
> function ($left, $right) {
>      return $left[1] <=> $right[1];
> }
> 

while that example is overly nice - in real world outside a usort
callback the consumer of the function in most cases still has to do the
three if cases to use the result. So in practical terms it is limited to
usort() and then it is a custom operator people reading the code most
likely have to lookup. Typically in PHP we try to have identifiers which
can be found via Google, Google doesn't handle "special" characters
well.

johannes




Thread (20 messages)

« previous php.internals (#72555) next »