Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28459 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41911 invoked by uid 1010); 19 Mar 2007 21:55:08 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 41896 invoked from network); 19 Mar 2007 21:55:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2007 21:55:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 63.205.162.114 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 63.205.162.114 unknown Windows 2000 SP4, XP SP1 Received: from [63.205.162.114] ([63.205.162.114:24211] helo=us-ex1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 76/B5-01604-AB60FF54 for ; Mon, 19 Mar 2007 16:55:07 -0500 Received: from [127.0.0.1] ([192.168.16.109]) by us-ex1.zend.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 19 Mar 2007 14:55:03 -0700 Message-ID: <45FF06B4.2060801@zend.com> Date: Mon, 19 Mar 2007 14:55:00 -0700 Organization: Zend Technologies User-Agent: Thunderbird 2.0b2 (Windows/20070116) MIME-Version: 1.0 To: ceo@l-i-e.com CC: Wez Furlong , Sean Coates , internals@lists.php.net References: <86478A67-DCA2-4000-9EF0-DA4338E8389B@omniti.com> <45FDF031.4010508@zend.com> <45FE2312.1050506@zend.com> <45FED6D9.8030307@caedmon.net> <45FEDAE5.2010309@zend.com> <45FEE396.7040905@caedmon.net> <0757BDEA-65F5-4123-B647-060DCA84B4B0@omniti.com> <32945.216.230.84.67.1174340098.squirrel@www.l-i-e.com> In-Reply-To: <32945.216.230.84.67.1174340098.squirrel@www.l-i-e.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 19 Mar 2007 21:55:03.0945 (UTC) FILETIME=[3FE94790:01C76A71] Subject: Re: [PHP-DEV] PATCH: anonymous functions in PHP From: stas@zend.com (Stanislav Malyshev) > This gets incredibly complex not only to figure out what to do in the > PHP source, but for scripters to figure out what the heck it does... Welcome to the world of closures :) But in most cases people use it to do pretty basic stuff (unless they are CS majors with too much time on their hands ;) - like creating "dynamic anonymous functions" - basically resulting in the same as what create_function does, and some currying - which, for those who doesn't know it, is technique of partially instantiating a multi-argument function - i.e. making something like: $addtwo = function ($a) { return $a+2; } $six = $addtwo(4); or more frequently something like this: $var = "foo"; $compare_to_var = function($s) { return (str_compare($var, $s)<0); } $strings_less_than_var = array_filter($array, $compare_to_var); which is really powerful technique for dynamic language, though can easily lead one to lose all track of what is happening if overused. For more confusion see http://en.wikipedia.org/wiki/Currying :) > If it's making YOUR head spin, what will it do to the poor unwashed > masses?... Unwashed masses better not do it :) Actually many "washed" masses have hard time to understand these things too. > I suspect that you could get away with JUST using global and/or static > as they exist now, not introduce yet another scoping keyword, and > anything that *NEEDS* to be done with an anonymous function can be > done. I guess this depends on definition of "NEEDS". > You have to have a pretty esoteric function to need that kind of scope > control, no? Depends on your background. Some people consider LISP intuitive language :) And if you work with Javascript, you probably would be doing it daily - most AJAX toolkits rely on heavy usage of anonymous functions. Not sure it needs to be in PHP though. It might be cool thing, but it's definitely becomes very confusing very fast. -- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/