Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28551 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59652 invoked by uid 1010); 22 Mar 2007 14:54:42 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 59637 invoked from network); 22 Mar 2007 14:54:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2007 14:54:42 -0000 Authentication-Results: pb1.pair.com header.from=michael.walter@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=michael.walter@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 64.233.182.189 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: michael.walter@gmail.com X-Host-Fingerprint: 64.233.182.189 nf-out-0910.google.com Linux 2.4/2.6 Received: from [64.233.182.189] ([64.233.182.189:8300] helo=nf-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AC/71-46365-0B892064 for ; Thu, 22 Mar 2007 09:54:41 -0500 Received: by nf-out-0910.google.com with SMTP id l35so1569230nfa for ; Thu, 22 Mar 2007 07:54:37 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=F9U4+Syt4G8XhLHnWe9COksQ7vV2S9yN25wPaGdKzbpoV2iikyk+P+u5tbM8MkA2dMzgGsBO6M/BoIMAozDfGOXzziMjaiqxUYqJyjefummC/C3tkR4deK5FEglNqgF5GLV9UsWEETFf2JBNIKq4xGJu2Lz9I+9MXQVHLfxujQI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=YSTT4AhP6RUCV6bq9XmHQ/1Tffk7PR/gK3VXSQUKb8i7GPE9tDkBxgXhvBewDUYo6+YFIbPcbPAoMg+g25IBkXsQnFjB8xbiYP5L7+S5NgRr0xP06zlPlDy35OFLOh0A34LptvuIIabKBUCCLFizg59hvWoAqoJoZcSd/Y22b5U= Received: by 10.78.151.3 with SMTP id y3mr1023032hud.1174575276584; Thu, 22 Mar 2007 07:54:36 -0700 (PDT) Received: by 10.78.131.14 with HTTP; Thu, 22 Mar 2007 07:54:36 -0700 (PDT) Message-ID: <877e9a170703220754u6cd52b66gf3fe056491c6c921@mail.gmail.com> Date: Thu, 22 Mar 2007 15:54:36 +0100 To: "Christian Schneider" Cc: internals@lists.php.net In-Reply-To: <46029216.9090205@cschneid.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <86478A67-DCA2-4000-9EF0-DA4338E8389B@omniti.com> <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> <877e9a170703220719w4badd5a6y4345b508b3866131@mail.gmail.com> <46029216.9090205@cschneid.com> Subject: Re: [PHP-DEV] PATCH: anonymous functions in PHP From: michael.walter@gmail.com ("Michael Walter") On 3/22/07, Christian Schneider wrote: > Michael Walter wrote: > > Which seems to fit Andi's $_SCOPE proposal. > > Yes, but is a point against a real closure proposal. I think the defining property of a "real" closure proposal is having the lexical scope available. So I guess we both agree on that something like $_SCOPE would be a useful thing to have. > >> He said real-life examples (-:C > > > > Is that like "enterprise" examples? ;) > > No, it's like non-textbook example (which can also run on a Bird of Prey > or a Klingon starship :-)) Closures become really useful when you start building abstractions on top of anonymous functions, since in the process of abstraction you often replace literals/constants by parameters (similar to how function parameters become useful when you start refactoring common code into functions ;). A simple real-life example is: function pick($member) { return create_function('$x', 'return $x->'.$member.';'); } which could be used e.g. in array_map(pick('age'), $people). Arguably, in this case you could as well write: array_map(function($p) {return $p->age;}, $people); but I believe it is easy to see how the problem generalizes. Regards, Michael