Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63797 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1684 invoked from network); 10 Nov 2012 03:46:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Nov 2012 03:46:43 -0000 Authentication-Results: pb1.pair.com header.from=quickshiftin@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=quickshiftin@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.42 as permitted sender) X-PHP-List-Original-Sender: quickshiftin@gmail.com X-Host-Fingerprint: 209.85.219.42 mail-oa0-f42.google.com Received: from [209.85.219.42] ([209.85.219.42:49988] helo=mail-oa0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/23-60301-12ECD905 for ; Fri, 09 Nov 2012 22:46:42 -0500 Received: by mail-oa0-f42.google.com with SMTP id j1so4874417oag.29 for ; Fri, 09 Nov 2012 19:46:38 -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=XvuPn0JMNpZ5CoApuTqQden6kYXDBGReV8IN/jN5L4Q=; b=yB6aPru5qdmVcIE55dz/QV2r2yIDRujnEh82mP9ZEKr2ZULbm23GP/P9sZ4GQq/vXc pfhhmppan9fF/ZqFkNnJKis9uYtiVDVnkvzrHwOgBk0Ns50tczCcl+ARsJGJZ+XgU5d2 uMnkUVjXxnw7DNMIcmX+kPFb8nftluCu0qkv1XSRP+APydmDa6qN5ufjbP/nr9ZQXLk2 iwtrP0xRd6jtrwCYQRGTGROXuI72fen18uVXtDYD1EbBkpsw+T0oGj1zmPxIujc21hYe Eo3MM4HSrRfWuXm3i8rN+mxjl8Ov7sbLe+WM/gLgnElFrxdGAWL3tkFbTRGEIUa8j4Tp P7YQ== MIME-Version: 1.0 Received: by 10.60.170.7 with SMTP id ai7mr9846765oec.20.1352519197927; Fri, 09 Nov 2012 19:46:37 -0800 (PST) Received: by 10.60.10.38 with HTTP; Fri, 9 Nov 2012 19:46:37 -0800 (PST) In-Reply-To: References: <4ED7146272E04A47B986ED49E771E347BB1318FD7E@Ikarus.ameusgmbh.intern> Date: Fri, 9 Nov 2012 20:46:37 -0700 Message-ID: To: jpauli Cc: Christian Stoller , PHP internals Content-Type: multipart/alternative; boundary=bcaec54a324a5827b704ce1beaa6 Subject: Re: [PHP-DEV] Object comparison From: quickshiftin@gmail.com (Nathan Nobbe) --bcaec54a324a5827b704ce1beaa6 Content-Type: text/plain; charset=UTF-8 On Fri, Nov 9, 2012 at 2:00 PM, jpauli wrote: > On Fri, Nov 9, 2012 at 2:18 PM, Christian Stoller > wrote: > > I would like to place a suggestion for comparing objects (I hope it is > no problem, because this does not have anything to do with Sara's question > - but it came to my mind when I read her mail). It would be a great feature > if objects could be compared to other objects with ">", "<" and the other > operators, like it is suggested in RFC https://wiki.php.net/rfc/comparable > > The DateTime class offers this feature - it would be nice if this could > be made usable for userland classes/objects, too. > > > I really like that idea, and the patch looks pretty good and looks > backward compatible. > I'm +1 with it > > I'm also +1 with patching the doc to describe the full default compare > behavior. > Another spot in the docs I would enjoy discussion about <,>,>=,<= comparing two objects: http://php.net/manual/en/language.oop5.object-comparison.php I notice this behavior is suggested in a comment for use in an array_uintersect callback: http://php.tonnikala.org/manual/el/function.array-uintersect.php#72841 Indeed, trying to intersect two arrays of objects with a user callback 'works' with the > comparison operator, but maybe this is just luck, or subject to BC break later? name = $name; } } $o1 = new myclass('o1'); $o2 = new myclass('o2'); $o3 = new myclass('o3'); $o4 = new myclass('o4'); $a1 = array($o1, $o2, $o3); $a2 = array($o3, $o2, $o4); var_dump(array_uintersect($a1, $a2, function($v1, $v2) { if($v1 === $v2) return 0; if($v1 > $v2) return 1; return -1; })); I'd expect the > comparison there to be roughly equivalent to if(spl_object_hash($v1) > spl_object_hash($v2)), no? Info on the default behavior here would be nice. -nathan --bcaec54a324a5827b704ce1beaa6--