Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83245 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39261 invoked from network); 19 Feb 2015 22:25:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2015 22:25:39 -0000 Authentication-Results: pb1.pair.com header.from=adam@adamharvey.name; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=adam@adamharvey.name; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain adamharvey.name designates 209.85.215.53 as permitted sender) X-PHP-List-Original-Sender: adam@adamharvey.name X-Host-Fingerprint: 209.85.215.53 mail-la0-f53.google.com Received: from [209.85.215.53] ([209.85.215.53:38606] helo=mail-la0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/A4-10294-FD266E45 for ; Thu, 19 Feb 2015 17:25:36 -0500 Received: by lamq1 with SMTP id q1so2633495lam.5 for ; Thu, 19 Feb 2015 14:25:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adamharvey.name; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=oQvXf9LrElzq3k6dezmhRCIrq9dKEUvnkDUeOiIMIas=; b=OYViAihWxY7Ei6dORv+1R+zfbexFbOPQdexsiTxPrv+fPEQbGdR5sXz9Epp/5Ig5rk yfyi0QCHHNtzQj6nDsfhFSUN9/30108P9GLWeGwSAEPrcZP3B+dO3jTxXT/7g8iHwD37 wS6aDw+WNn+BsAQWR6UhIJTN5o/8X0udIzBOQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=oQvXf9LrElzq3k6dezmhRCIrq9dKEUvnkDUeOiIMIas=; b=DceP5e5wqlNTD9IqjZg2YYGZVlzKJdrpNP9jdxBEg70J6rY8PmsyK/UcRsFcCM2U3n 6qGp9nhwtW3BpKQlBTnkCh3Akvlp45yiXx9d239qZyT/L6Alk3cviR9B5CA5JB/6QDYo CFCBfHqfPcPtwqPqiIJY33JtrdbgNSTsz87tX3/41W5mocjE1s1+RmsFW09sYWUh0wwc F0KtYI+euEhDmvbxvzkEJImLTJRnk1fSB0smlqagh8lcWJJxgqVDGcx+iP81ZPBQNTS1 4dJ9qYCMJEH3auWXP5rbKkVdjmnzCV56SrcnK8Y7Tf4XkhTpZp4jFAvYU4hZLxyBP1Dn zEQw== X-Gm-Message-State: ALoCoQlJL/jnPBIFyDYNR8EChO7oPTznRFWqKUQzTthbAKSJrPQB5VEsCZqwCG2P6PicOa0RXhlR X-Received: by 10.152.198.203 with SMTP id je11mr5940044lac.48.1424384731389; Thu, 19 Feb 2015 14:25:31 -0800 (PST) MIME-Version: 1.0 Sender: adam@adamharvey.name Received: by 10.113.4.164 with HTTP; Thu, 19 Feb 2015 14:25:11 -0800 (PST) In-Reply-To: References: Date: Thu, 19 Feb 2015 14:25:11 -0800 X-Google-Sender-Auth: JWqlmb2Oo-1HE-09rTZ4DGDPUwQ Message-ID: To: Levi Morrison Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Comparable: the revenge From: aharvey@php.net (Adam Harvey) I don't want to get into a lengthy debate (you have your opinion; I have mine!), but to rebut a couple of specific points: On 19 February 2015 at 14:19, Levi Morrison wrote: > Another issue: it allows comparing an object to non-objects (even > though the stated goal is only to compare two objects of the same > type): This is intentional. The wording in the introduction is probably a little too specific to the object case =E2=80=94 I'll fix that. > class MyClass implements Comparable { > private $val =3D 0; > function compareTo($a) { > return $this->val <=3D> $a; > } > } > > $int =3D 10; > $myClass =3D new MyClass(); > $myClass <=3D> $int; // works > $int <=3D> $myClass; // if this doesn't produce a warning it at least > doesn't behave the same as the line above it It does behave the same as the line above (with the result inverted, obviously) =E2=80=94 MyClass::compareTo() is still called in this case. The only time ordering matters is if two objects are being compared, in which case the leftmost one is the one that has its compareTo() method called. > But even here I would rather just take a function instead of requiring > it to be the instance of some interface: > > function sort($input, callable $comparator($a, $b): int) { > /* =E2=80=A6 */ > } Fair, but the sorting case isn't the only one that matters, particularly with <=3D> now as part of the language. > I do want to thank you for taking the time to cite arguments, prior > history and an alternative in the RFC. You have done a pretty good job > on the RFC itself, in my opinion. Thanks. :) Adam