Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87971 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2434 invoked from network); 1 Sep 2015 03:09:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2015 03:09:08 -0000 Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.97 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.97 blu004-omc2s22.hotmail.com Received: from [65.55.111.97] ([65.55.111.97:52582] helo=BLU004-OMC2S22.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B7/C8-39890-2D615E55 for ; Mon, 31 Aug 2015 23:09:07 -0400 Received: from BLU436-SMTP233 ([65.55.111.72]) by BLU004-OMC2S22.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Mon, 31 Aug 2015 20:09:02 -0700 X-TMN: [05bK7ZbQ6kkKn1rS4tSjCjM+R2cRbVYI] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) In-Reply-To: <7BCB36EE-56C8-441F-BF40-954D9FA912A9@lerdorf.com> Date: Tue, 1 Sep 2015 05:08:57 +0200 CC: Stanislav Malyshev , Nikita Nefedov , "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable References: <55E4C19F.4060704@gmail.com> <55E4F029.10104@gmail.com> <7BCB36EE-56C8-441F-BF40-954D9FA912A9@lerdorf.com> To: Rasmus Lerdorf X-Mailer: Apple Mail (2.2098) X-OriginalArrivalTime: 01 Sep 2015 03:09:00.0224 (UTC) FILETIME=[8C679C00:01D0E463] Subject: Re: [PHP-DEV] [RFC] [Discussion] Short Closures From: bobwei9@hotmail.com (Bob Weinand) > Am 01.09.2015 um 04:55 schrieb Rasmus Lerdorf : >=20 >> On Aug 31, 2015, at 18:04, Bob Weinand wrote: >>=20 >> =46rom the RFC: >>> all variables used in the body of the anonymous function will = automatically be bound to the anonymous function closure from the = defining scope >>=20 >> The implementation is not capturing all the variables from the outer = scope, but strictly only these accessed by the variables in the Closure = itself. Hence that shouldn't be much of an issue. >=20 > This magic scares me. I made a very deliberate decision In the very = first implementation of PHP to avoid scope side-effects like this. = Inside a function everything is local unless explicitly declared not to = be. This has carried through for the past 20+ years in slightly = different ways, but the basic rule has stayed consistent even for = closures. Unless explicitly declared via a use clause, every variable = inside a closure is local and no cross-scope variable name side-effects = are possible. I am not convinced that this feature is worth breaking = that longstanding basic tenet of the language. >=20 > -Rasmus I'd like to note that it's binding by value and not by reference nor = true closing over. There are no side effects, only importing of the variables. Also, as stated, an important application is quick closures to be passed = to e.g. array_map: /* increment by $y */ $y =3D 10; $array =3D array_map($x ~> $x + $y, $array); Here it is very obvious that we want to import a variable. Especially, I = wonder how $array =3D array_map(function ($x) use ($y) { return $x + $y; }, = $array); is making such simple applications more readable? And especially, what = value does it add here? If you want to be scoping-safe, (e.g. in bigger Closures inside a large = function), there always is the explicit syntax allowing you to do that. Short Closures are a tool for certain use cases, not a swiss knife. Bob P.s.: Just a side-question ... Why did you then think, it's be a great = idea for include/require to share scope?=