Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72548 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36562 invoked from network); 13 Feb 2014 07:56:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Feb 2014 07:56:15 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.52 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.212.52 mail-vb0-f52.google.com Received: from [209.85.212.52] ([209.85.212.52:56515] helo=mail-vb0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/B1-27664-E9A7CF25 for ; Thu, 13 Feb 2014 02:56:14 -0500 Received: by mail-vb0-f52.google.com with SMTP id p14so8005192vbm.11 for ; Wed, 12 Feb 2014 23:56:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=nxmDT4ZkUdO+PEP+HT+BqBp1HegGa4C/cZUwwe+Sw3g=; b=z2RecntTLbae+8H4U2GQbcx6e8ReDYz7ngoyURQsDN/DNVd63n2ewPyq8aZoOt/NoA kdoZoR2KCbAGj2bYn80urzsnKYyA6g8wLPWGne2pF8WaoMYZwPL6hGKYPiogmj7etRQ5 P2snCh+AU15ZYH7FAl3C0DE+0ILK/w1SLaSfionVTLNKLFaEVB/6xQh/rDgMLU3VK6qx ovvL23qJousCbbYtXBpLW/3p0KyX2LSLRllqBfOJAqXXnwgNArq6TDhBDGvvgKbduaHO Si7cKghHIuDsU1mXX58UvBa+q/LOTvNH7bOQB5Un+FMNrZ8OwyZQkhETTmOCWZUiBcog Lu8w== MIME-Version: 1.0 X-Received: by 10.221.30.14 with SMTP id sa14mr47041vcb.44.1392278171452; Wed, 12 Feb 2014 23:56:11 -0800 (PST) Received: by 10.58.133.229 with HTTP; Wed, 12 Feb 2014 23:56:11 -0800 (PST) In-Reply-To: <4ED7146272E04A47B986ED49E771E347BBC71EE997@Ikarus.ameusgmbh.intern> References: <4ED7146272E04A47B986ED49E771E347BBC71EE997@Ikarus.ameusgmbh.intern> Date: Thu, 13 Feb 2014 15:56:11 +0800 Message-ID: To: Christian Stoller Cc: Davey Shafik , "internals@lists.php.net" , Simon J Welsh Content-Type: multipart/alternative; boundary=001a11336a2ed6899604f24505be Subject: Re: [PHP-DEV] [RFC] Combined Comparison Operator From: tjerk.meesters@gmail.com (Tjerk Meesters) --001a11336a2ed6899604f24505be Content-Type: text/plain; charset=ISO-8859-1 On Thu, Feb 13, 2014 at 3:19 PM, 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`? > This only works on numbers, and integers in particular, because of how the result of a comparison function is cast. For example, `0.4f - 0.5f` equals `-0.1f` but gets cast to `0` when it's converted to a long value. See also: http://lxr.php.net/xref/PHP_5_6/ext/standard/array.c#597 > > 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 > -- -- Tjerk --001a11336a2ed6899604f24505be--