Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81592 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45348 invoked from network); 2 Feb 2015 16:07:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 16:07:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.180 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.180 mail-ob0-f180.google.com Received: from [209.85.214.180] ([209.85.214.180:47649] helo=mail-ob0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1C/D1-34915-6A0AFC45 for ; Mon, 02 Feb 2015 11:07:04 -0500 Received: by mail-ob0-f180.google.com with SMTP id vb8so17212375obc.11 for ; Mon, 02 Feb 2015 08:06:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=lTrVDTBRDbZ2Ej7+A4utRRwuhpaAMgqu5r9zqIQIvPE=; b=HGkKZCqOZU5kVImUc8FjOV4Cv6kU0y0WYeB+hIFscan96ipcfO5DatgicFKHf87ESW FGikudTWbC+VoZZov/VHejdeW7CpAaZDGR9liLh9432cyyEpeoSbVBHTtYI8msCAwnQ+ I1osQT1crUWd19zMtAw33WC0hwzWxD7l5rj+3I/+R7plylCfSKgES2WiteWk8eGz3dLL 4pdkO84h0Dvi1apyCrxIGTQbSFjgARghfCDvCfr+Y5qXF/H70mMl0ReGbCu+opPI+v0H vZcma2s3NnmDwE1vpMEkPkK49pNzQdd42agle1NMeYhmV3JBTvqySNWdM9A/JiF4vDbp +hUg== MIME-Version: 1.0 X-Received: by 10.202.184.70 with SMTP id i67mr11696267oif.68.1422893219624; Mon, 02 Feb 2015 08:06:59 -0800 (PST) Sender: morrison.levi@gmail.com Received: by 10.76.103.37 with HTTP; Mon, 2 Feb 2015 08:06:59 -0800 (PST) In-Reply-To: <1D2674AE-6DA6-42A4-817E-0166F30B667D@ajf.me> References: <1D2674AE-6DA6-42A4-817E-0166F30B667D@ajf.me> Date: Mon, 2 Feb 2015 09:06:59 -0700 X-Google-Sender-Auth: 99SGa80s0bHfAyf_3fP56wXQYgQ Message-ID: To: Andrea Faulds Cc: Nikita Popov , PHP Internals List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Combined Comparison (Spaceship) Operator From: levim@php.net (Levi Morrison) On Mon, Feb 2, 2015 at 8:27 AM, Andrea Faulds wrote: > Hey Nikita, > >> On 2 Feb 2015, at 13:49, Nikita Popov wrote: >> >> I've voted -1 because I think this should be a function and not an opera= tor. compare($a, $b) is more obvious than $a <=3D> $b and it's not like wri= ting comparison functions is such a super common use case that it needs the= extra brevity of an operator. A function can furthermore be used as a call= back, while an operator requires a wrapping closure. > > There=E2=80=99s no actual use for the bare comparison operation as a call= back, though: usort($foo, =E2=80=98compare=E2=80=99); would just be a slow = version of sort($foo); For this particular use-case you are correct, but usually I use custom callbacks for something more interesting, such as comparing one value and then comparing another based on the result. Perhaps the callback is higher-level: function (callable $comparator) { return function ($selector) use ($comparator) { return function ($a, $b) use($selector, $comparator) { return $comparator($selector($a), $selector($b)); }; }; } Maybe I'm the only one doing stuff like this, but it's not uncommon for me = ^^