Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49820 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67561 invoked from network); 30 Sep 2010 15:13:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Sep 2010 15:13:39 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:32937] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 76/05-43687-129A4AC4 for ; Thu, 30 Sep 2010 11:13:38 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id BEC627000432 for ; Thu, 30 Sep 2010 16:13:34 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id LEDRRY8PQA2L for ; Thu, 30 Sep 2010 16:13:34 +0100 (WEST) Received: from mail2.ist.utl.pt (mail2.ist.utl.pt [IPv6:2001:690:2100:1::c]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 73AD67000430 for ; Thu, 30 Sep 2010 16:13:34 +0100 (WEST) Received: from damnation (a79-168-249-157.cpe.netcabo.pt [79.168.249.157]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 651F520079A3 for ; Thu, 30 Sep 2010 16:13:34 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: Date: Thu, 30 Sep 2010 16:13:40 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_IST?= Message-ID: In-Reply-To: User-Agent: Opera Mail/10.62 (Win32) Subject: Re: [PHP-DEV] RFC: Comparable interface From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Thu, 30 Sep 2010 14:33:05 +0100, Adam Harvey wrote:= > I've just written an RFC (with a patch against trunk) to implement a > Comparable interface similar to that in Java =E2=80=94 in effect, allo= wing > object instances to be compared with semantics defined in userspace. > This is admittedly at the lower end of RFC-worthy proposals, but it's > a good system, and I'd like to see it used a little more. Plus, it's > good practice for the more interesting stuff to come. :) > > The RFC is at http://wiki.php.net/rfc/comparable, and the patch at > http://www.adamharvey.name/patches/comparable.diff.txt. Any and all > feedback welcome, particularly since I'm still learning my way around > the innards of the Zend Engine, and it's entirely possible (indeed, > likely) that I've overlooked something obvious. > > If there's no great resistance to the concept or implementation, I'm > happy enough to flip this into the voting stage sooner rather than > later so we can get it out of the way. > I think this would be a good idea if limited to provide a userspace = alternative to compare_objects, like Countable provides a userspace = alternative to count_elements. That is, you would only modify zend_std_compare_objects (not = compare_function!) and add there the additional logic where you'd check = if = the objects had the same class (or perhaps one was of a subclass of the = = other, in which case you'd use the compare method of the subclass) and = call the compare method. Allowing comparison of objects with non-objects can become very confusin= g: * What if the objects are not of the same class? What if one is of a = subclass of the other? Is equality not symmetric? * How do you interact with 'get' and 'cast_object'/'__tostring'? It's true that there's already overloading of '=3D=3D' for internal clas= ses, = but it's very predictable: both operands must have the same = 'compare_objects', otherwise it's not used. For the record, the current rules are relatively simple: * If both are objects and have the same 'compare_objects' handler, use i= t. * If the first operand is an object and has a 'get' (tried first) or = 'cast_object' handler call it, and repeat with the new value. * Try the same for the second operand. -- = Gustavo Lopes