Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34070 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28946 invoked by uid 1010); 17 Dec 2007 19:38:03 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 28931 invoked from network); 17 Dec 2007 19:38:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Dec 2007 19:38:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=troelskn@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=troelskn@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.198.191 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: troelskn@gmail.com X-Host-Fingerprint: 209.85.198.191 rv-out-0910.google.com Received: from [209.85.198.191] ([209.85.198.191:17133] helo=rv-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/C6-20687-810D6674 for ; Mon, 17 Dec 2007 14:38:02 -0500 Received: by rv-out-0910.google.com with SMTP id k15so1979069rvb.23 for ; Mon, 17 Dec 2007 11:37:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=eaJeGBgCFgSg/HNhQQdy2Mp87kralx1scU6NKl1N0E8=; b=VnzlToO5M/jprf1LcUhfJx22zIQvoBgHYFL3lsCUlMwAjhQeCjNN40nVU97mvW4V3NWNkxvstxNsiLpri6IEk/usS+zC2AT3pHhxpknxiLoSuvHxHTIrqMbezetNWx+bsVTcsU0Z9Abdkp8Eqq/UFtAraVDYgajglT3BoyP8KUI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=sZKO0ZFKpWcrEwroIpmjgcIxYs2kyOZbYgLSG9bUMj4HA6xCNiEcJae99ksYOaxyhBDmBGOZZDiKDxVFhPBZshWcmowa42IW6Yt91RYTDELxNCgFVGLMlLnPCKHO2Ao2itdY8vPjf9tjz3R8XCZEUdkiStf41adduwUXIgX6lyQ= Received: by 10.140.144.4 with SMTP id r4mr1565004rvd.15.1197920277751; Mon, 17 Dec 2007 11:37:57 -0800 (PST) Received: by 10.141.50.16 with HTTP; Mon, 17 Dec 2007 11:37:57 -0800 (PST) Message-ID: <98b8086f0712171137k5ac9b4aau4a720662b0ba99be@mail.gmail.com> Date: Mon, 17 Dec 2007 20:37:57 +0100 To: internals@lists.php.net In-Reply-To: <698DE66518E7CA45812BD18E807866CE0108180B@us-ex1.zend.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <98b8086f0712150818n40056cedyf0aae7a5a08a27b7@mail.gmail.com> <4764CC64.3040608@zend.com> <623025726.20071217140947@marcus-boerger.de> <698DE66518E7CA45812BD18E807866CE0108180B@us-ex1.zend.net> Subject: Re: [PHP-DEV] Re: PATCH: anonymous functions in PHP From: troelskn@gmail.com ("troels knak-nielsen") On Dec 17, 2007 6:09 PM, Andi Gutmans wrote: > Don't have time right now but we should go back and re-read those > discussions before opening a new one. I can probably do it over the next > couple of days. I am not necessary against supporting such a solution > but we need to make sure it's fully baked and that we clear know and > agree on what is and what isn't supported (and that should be documented > and not revisited every time someone comes and complains). Variable > binding is one thing which would likely not make it into such an > implementation unless there's a big shift in the intent of the patch. Allow me to recap then. Static lambdas (in lack of a better name) and create_function() differ from each other in that the former happens at compile time, while the latter happens at run time. The consequence of this is, that you can bind (primitive) variables to the created function, with create_function(), but not with static lambdas. Functionally, create_function() is a variation of eval, which allows you to create new code at runtime. Static lambda is syntactic sugar for creating a function in the global scope, without knowing its name at compile time. Static lambda is more restrictive than create_function(), because there is no way to share scope between the inner and the bounding function. This is specific for PHP, because the language doesn't have static scope. Without going much into details, I think it's pretty safe to say, that introducing static scope into PHP is not only undesireable, but also technically impossible. So let's not spend any time discussing that. In brief, there are the following benefits of introducing static lambdas: A1 Better readability. A2 Syntactic errors happen at compile time, rather than run time. A3 Better support for debugging/introspection. A4 Optimisations are possible. And the following problems: B1 Users might assume, that lambdas have static scope. B2 There is some overlap between the application of create_function() and static lambdas, meaning some level of redundancy. B3 Static lambdas are less powerful, since there is no way to bind variables. If I missed any points, please bring them up. Otherwise, this is what a decision should be based on. (And sorry for pointing out the obvious, but _not_ making a decision, is a decision too) Of the cons, B1 is probably the biggest issue. There are (at least) two considerations to take here; First, how probable is it, that users will make this assumption? And second, how much confusion will it cause to those, which it affects? The first question could perhaps be answered by a survey (Or less scientifically, by random consensus), but the latter is rather subjective. I'd like to make the argument, that those who will tend to suffer most from peculiarities of scoping rules, are the same people, who are less likely to have encountered static scope in the first place. The simple rule, that PHP has dynamic scope, should be simple to understand for anyone who actually knows the difference. Did I miss anything? -- troels