Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72557 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96927 invoked from network); 13 Feb 2014 15:30:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Feb 2014 15:30:11 -0000 X-Host-Fingerprint: 72.91.185.17 pool-72-91-185-17.tampfl.fios.verizon.net Received: from [72.91.185.17] ([72.91.185.17:20716] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C9/23-09050-105ECF25 for ; Thu, 13 Feb 2014 10:30:09 -0500 To: internals@lists.php.net,Christian Stoller , Message-ID: <52FCE4FC.6010204@php.net> Date: Thu, 13 Feb 2014 10:30:04 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 "internals@lists.php.net" CC: Simon J Welsh References: <4ED7146272E04A47B986ED49E771E347BBC71EE997@Ikarus.ameusgmbh.intern> In-Reply-To: <4ED7146272E04A47B986ED49E771E347BBC71EE997@Ikarus.ameusgmbh.intern> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 72.91.185.17 Subject: Re: [PHP-DEV] [RFC] Combined Comparison Operator From: davey@php.net (Davey Shafik) On 2/13/14, 2:19 AM, Christian Stoller wrote: > Davey Shafik 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 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 > 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 - Davey