Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28550 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57420 invoked by uid 1010); 22 Mar 2007 14:49:19 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 57405 invoked from network); 22 Mar 2007 14:49:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2007 14:49:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=sean@caedmon.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sean@caedmon.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain caedmon.net from 69.60.120.90 cause and error) X-PHP-List-Original-Sender: sean@caedmon.net X-Host-Fingerprint: 69.60.120.90 iconoclast.caedmon.net Linux 2.4/2.6 Received: from [69.60.120.90] ([69.60.120.90:51665] helo=iconoclast.caedmon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 61/31-46365-F6792064 for ; Thu, 22 Mar 2007 09:49:19 -0500 Received: from localhost ([127.0.0.1]) by iconoclast.caedmon.net with esmtp (Exim 3.35 #1 (Debian)) id 1HUObE-0000PX-00; Thu, 22 Mar 2007 10:49:08 -0400 Message-ID: <4602976B.5040909@caedmon.net> Date: Thu, 22 Mar 2007 10:49:15 -0400 User-Agent: Thunderbird 1.5.0.10 (X11/20070307) MIME-Version: 1.0 To: Stefan Walk CC: internals@lists.php.net References: <86478A67-DCA2-4000-9EF0-DA4338E8389B@omniti.com> <45FEFDCE.7050100@zend.com> <1174339527.24632.129.camel@blobule> <45FF01FE.6070504@zend.com> <698DE66518E7CA45812BD18E807866CE185525@us-ex1.zend.net> <698DE66518E7CA45812BD18E807866CE18559A@us-ex1.zend.net> <40259.216.230.84.67.1174435351.squirrel@www.l-i-e.com> <877e9a170703220436l267d2648jc99aaaf9cccecfdd@mail.gmail.com> <46028001.7060204@cschneid.com> <4858f9d90703220731g3752d1e8w368f59f30ddb8086@mail.gmail.com> In-Reply-To: <4858f9d90703220731g3752d1e8w368f59f30ddb8086@mail.gmail.com> X-Enigmail-Version: 0.94.2.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PATCH: anonymous functions in PHP From: sean@caedmon.net (Sean Coates) > function sort_by_key($key) { For the record, I do like this syntax, but it COULD be rewritten using current practices (see below). class SortByKey { public $key; public function __construct($key) { $this->key = $key; } public function do($a, $b) { if ($a[$this->key] < $b[$this->key]) return -1; if ($a[$this->key] == $b[$this->key]) return 0; return 1; } } $a = array( array('id' => 0, 'first_name' => 'john', 'last_name' => 'connor'), ... ); $Sorter = new SortByKey('last_name'); usort($a, array($Sorter, 'do')); That said, I like the idea of a first class callable object. For the example above, doing this: class SortByKey implements Callable { ... $Sorter(); Would actually execute $Sorter->do(); (obviously there's a problem when $Sorter has a __toString (dynamic function call), but this seems to nicely wrap all but the most basic case of callback, where an object might be overkill. Perhaps this could be implemented in SPL? (Just wondering if it's possible at this point, I'm not campaigning for it..) S