Re: [RFC] Combined Comparison Operator
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)