Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67348 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91164 invoked from network); 7 May 2013 19:15:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 May 2013 19:15:19 -0000 Authentication-Results: pb1.pair.com header.from=jake@theunraveler.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jake@theunraveler.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain theunraveler.com designates 67.222.54.6 as permitted sender) X-PHP-List-Original-Sender: jake@theunraveler.com X-Host-Fingerprint: 67.222.54.6 oproxy6-pub.bluehost.com Linux 2.6 Received: from [67.222.54.6] ([67.222.54.6:53847] helo=oproxy6-pub.bluehost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/A3-06696-5C259815 for ; Tue, 07 May 2013 15:15:18 -0400 Received: (qmail 24143 invoked by uid 0); 7 May 2013 19:15:11 -0000 Received: from unknown (HELO box689.bluehost.com) (66.147.244.189) by cpoproxy3.bluehost.com with SMTP; 7 May 2013 19:15:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=theunraveler.com; s=default; h=To:References:Message-Id:Content-Transfer-Encoding:Date:In-Reply-To:From:Subject:Mime-Version:Content-Type; bh=vsqta732knDSD+naQbw39eTf5FdQs5sq/r4nbsXyT0g=; b=Bzl7BViyVugufCAHvIJhF6BIoX1HD3LBkdH+nzEkpcwS4ByzXjpRkbfBI7SBWkF0cwDPVJXjauGdlXNfHbWCFOf+ZHXRSH2QpXLhmBXGMucnvnOMo0v3YR+c8COKATws; Received: from [67.6.55.224] (port=65223 helo=[192.168.0.3]) by box689.bluehost.com with esmtpsa (TLSv1:RC4-SHA:128) (Exim 4.80) (envelope-from ) id 1UZnLx-0006Lr-Cc for internals@lists.php.net; Tue, 07 May 2013 13:15:09 -0600 Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) In-Reply-To: Date: Tue, 7 May 2013 14:15:08 -0500 Content-Transfer-Encoding: quoted-printable Message-ID: <73F8DE8F-5AC8-4BBD-B4DE-C4AF1CB37EAB@theunraveler.com> References: To: PHP internals X-Mailer: Apple Mail (2.1503) X-Identified-User: {2113:box689.bluehost.com:iamtheun:theunraveler.com} {sentby:smtp auth 67.6.55.224 authed with jake@theunraveler.com} Subject: Re: [PHP-DEV] idea: implement a Comparable interface From: jake@theunraveler.com (Jake Bell) I proposed something similar recently in the PHP-FIG group, but decided = that without the language-level ability to overload comparison = operators, standardizing comparables ony using methods was not very = useful. If PHP could provide a magic method for comparison that involved = being able to use comparison operators, I think this feature would be = really useful. An example that comes to mind is a Money class: $pesos =3D new Money(200, Money::PESO); $dollars =3D new Money(100, Money::US_DOLLAR); var_dump($pesos < $dollars); Then, the Money class could take care of normalizing and comparing the = values. Food for thought... -- Jake On May 7, 2013, at 1:15 PM, Stuart Langley wrote: > Classes without the ability to overload the comparison operator could = be > considered kinda useless as well. >=20 >=20 > On Tue, May 7, 2013 at 11:11 AM, Daniel Ribeiro = wrote: >=20 >> Its kinda useless feature for PHP. >>=20 >>=20 >> Daniel Ribeiro Gomes Pereira >> Twitter | >> Facebook >> | LinkedIn = >> iPhone: +55 (48) 9111-0931 >>=20 >>=20 >> 2013/5/7 Nikita Popov >>=20 >>> On Tue, May 7, 2013 at 6:17 PM, Thomas Anderson >> wrote: >>>=20 >>>> It'd be nice if, when doing $objA > $objB, that that'd invoke >>>> $objA->__compareTo($objB) or something, much like Java's Comparable >>>> interface. >>>>=20 >>>=20 >>> Do you have examples of what this would be useful for? The two = things >> that >>> come to mind are DateTime (which can do this anyway as it's an = internal >>> class) and classes for bignums or something like that (which are = probably >>> also better implemented internally). So I'm not sure how much use = there >> is >>> for this. >>>=20 >>> Nikita >>>=20 >>=20