Re: [RFC] Combined Comparison Operator
| From: | Davey Shafik | Date: | Thu, 13 Feb 2014 15:30:04 +0000 |
| Subject: | Re: [RFC] Combined Comparison Operator | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-72557@lists.php.net to get a copy of this message | ||
On 2/13/14, 2:19 AM, Christian Stoller wrote:
Davey Shafik <davey@php.net> wrote:This operator DOES work on arrays/objects. The fact it also works on scalar values is a bonus if that's how you want to look at it :P - DaveyThis 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 - $binstead of$a <=> $b? Simon J Welsh <simon@simon.geek.nz> 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