Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49834 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67044 invoked from network); 1 Oct 2010 02:57:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Oct 2010 02:57:41 -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.214.170 as permitted sender) X-PHP-List-Original-Sender: adam@adamharvey.name X-Host-Fingerprint: 209.85.214.170 mail-iw0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:43170] helo=mail-iw0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/77-18648-42E45AC4 for ; Thu, 30 Sep 2010 22:57:41 -0400 Received: by iwn37 with SMTP id 37so3804129iwn.29 for ; Thu, 30 Sep 2010 19:57:38 -0700 (PDT) Received: by 10.231.10.200 with SMTP id q8mr4893398ibq.83.1285901858665; Thu, 30 Sep 2010 19:57:38 -0700 (PDT) MIME-Version: 1.0 Sender: adam@adamharvey.name Received: by 10.231.79.3 with HTTP; Thu, 30 Sep 2010 19:57:18 -0700 (PDT) In-Reply-To: <4CA4F301.1070005@sugarcrm.com> References: <4CA4F301.1070005@sugarcrm.com> Date: Fri, 1 Oct 2010 10:57:18 +0800 X-Google-Sender-Auth: dxZFWqtetradKcwJU9UmpFn37VE Message-ID: To: Stas Malyshev Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] RFC: Comparable interface From: aharvey@php.net (Adam Harvey) For what it's worth, I'm planning to update the RFC later today with an updated SPL-less patch and the start of a Q&A section similar to what we've had in the other RFCs. I'll send an e-mail when it's ready. On 1 October 2010 04:28, Stas Malyshev wrote: > It is not clear from the RFC, if the engine encounters $a <= $b, what > actually happens? > E.g.: > 1. Is only $a checked for Comparable or also $b? Both $a and $b are checked. > 2. How it is ensured that if $a < $b then $b > $a? That's up to the userspace developer to get right when they're implementing their compareTo method. I expect the manual would have a dire warning about the possible consequences of not making them equivalent. > 3. Would sorting work with it? Yes. > 4. If both $a and $b are objects with different compare functions, how it is > determined whose function is used? Note that operators like == are assumed > to be commutative, and less/more operators are assumed to be commutative in > pairs, like above. The left operand wins, so $a. > As a side note, if we have traits we might instead think of having > Comparable trait or interface or both, which would declare having > compareTo() standard feature (as Java does) without messing with the engine > and overloading operators. Surely, it would be more verbose, but that might > be a good thing. I don't think that gains us an awful lot (it's no different to simply having an interface or trait within a codebase requiring such a function, which has been common practice in some of the systems I work on anyway), but it'd be easy enough to add, obviously. Adam