Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42481 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80186 invoked from network); 5 Jan 2009 10:24:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jan 2009 10:24:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; 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:39844] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/BC-07052-1FFD1694 for ; Mon, 05 Jan 2009 05:24:51 -0500 Received: from MBOERGER-ZRH.corp.google.com (137-5.203-62.cust.bluewin.ch [62.203.5.137]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 4978811F342; Mon, 5 Jan 2009 11:24:46 +0100 (CET) Date: Mon, 5 Jan 2009 11:21:56 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <832011302.20090105112156@marcus-boerger.de> To: Stanislav Malyshev CC: internals@lists.php.net, Dmitry Stogov , Lukas Kahwe Smith , =?iso-8859-15?Q?Johannes_Schl=FCter?= In-Reply-To: <496194BC.9040401@zend.com> References: <272365052.20090104173130@marcus-boerger.de> <496194BC.9040401@zend.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Closures, Lambdas and use From: helly@php.net (Marcus Boerger) Hello Stanislav, Monday, January 5, 2009, 6:03:56 AM, you wrote: > Hi! >> some time back (August 08) I complained about 'use' being at a weird >> position and not at the same place as 'global' or 'static' where I >> expected it. Back then Dmitry asked me to provide a patch to check out >> the alternative. Now during the holidays I finally found some time to >> change from: >> $f = function() use ($x) {} >> to: >> $f = function() { use $x; } >> >> Patch is attached. >> >> Comments? > I don't really see any "consistency" in it - this "use" syntax has > nothing to do with other "use" (namespace one) even if it looks almost > exactly like one in proposed patch. It also is subtly different from > global or static - different enough to make people think "ok, 'global' > is always by ref and 'use' looks like 'global' for consistency reasons - > does it mean it is consistently by-ref?" Not to mention questions like > "can I write 'use' in the middle of the code, since I can do it with > "consistent" constructs like 'static' or 'global'? What if I refer to > the variable before - will it be already bound?", etc. I think it would > not improve code readability and not really make it "consistent" anyway. We have the same with global and static. Can you write them in the middle of a funciton/method? So asking for what the consequence is, is irrelevant unless you want to clean up that mess and correct the parser rules knowing that it would break most PHP applications out there. Next, we chose 'use' for the keyword, knowing that it was already used elsewhere, dciding that it is the lesser evil opposed to creating yet another keyword with all implications of that. So this part is irrelevant to my point as well. What is left is moving something we decided upon so that it might look like something that is similar already avoiding to create a pretty new syntax that in my opinion is unnecessary different from anything we already have. In fact 'use' means create a static variable from the surrounding context, while 'static' means create a new static variable. Actually the executor does not know the difference at all. Next 'global' means allow to use a global variable. So: function () { global $foo; static $bar; use $baz; } Is pretty clear to me, as all three statements have a defined keyword. And I would really prefer if all I have to teach is the meaning of the keyword. And not having to teach a completely new syntax: function() use($baz) { global $foo; static $bar; } That simply contradicts the KISS approach because it requires one additional level of understanding. And to answer the other question. Obviously 'sttaic' and 'use' are executed at compile time, so whereever you place them, they are executed before anything else. Thus it doesn't matter where you place them. So here consistency means placing a syntactical element at the same syntactical location related syntactical elements are placed. Best regards, Marcus