Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40883 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39028 invoked from network); 8 Oct 2008 22:50:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Oct 2008 22:50:02 -0000 Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:54452] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/A2-48736-9193DE84 for ; Wed, 08 Oct 2008 18:50:02 -0400 Received: from MBOERGER-ZRH.corp.google.com (43-97.107-92.cust.bluewin.ch [92.107.97.43]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id C492411EFA6; Thu, 9 Oct 2008 00:49:58 +0200 (CEST) Date: Thu, 9 Oct 2008 00:47:08 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1848943374.20081009004708@marcus-boerger.de> To: Jeremy CC: internals@lists.php.net In-Reply-To: <2E.42.48736.AB7EBE84@pb1.pair.com> References: <2E.42.48736.AB7EBE84@pb1.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] RFC: SPL Comparator interface From: helly@php.net (Marcus Boerger) Hello Jeremy, Wednesday, October 8, 2008, 12:50:23 AM, you wrote: > Something that would be extremely useful is a comparator interface in > SPL, which could be used to easily implement sorting for objects. > Example: > class Foo implements Comparator > { > // is numeric for this example > public $bar; > //implements compare method from Comparator interface > public function compare($that) > { > //simple example; will return < 1 if this is less > //than that; zero if they're equal; > 1 if this is > //greater than that > return $this->bar - $that->bar; > } > } > Then, if I had an array of Foo objects, I could just call some kind of > spl_sort function on the array which would use my comparator to sort them. > I realize this can be kludged with usort(), but I think there should be > a better, OOP-ier way to do it. And for that exact reason we are adding closures in PHP 5.3. Best regards, Marcus