Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98112 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25574 invoked from network); 1 Feb 2017 23:06:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2017 23:06:10 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.51 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.51 mail-wm0-f51.google.com Received: from [74.125.82.51] ([74.125.82.51:35271] helo=mail-wm0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/A6-51557-1E962985 for ; Wed, 01 Feb 2017 18:06:10 -0500 Received: by mail-wm0-f51.google.com with SMTP id b65so63003472wmf.0 for ; Wed, 01 Feb 2017 15:06:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=A2tCydh/CLQsBjKQiGDPAQCXvbEKtwUUqZhnhpd2SIM=; b=RxYNrIpyBZwH5dK7vFE7MpLiwMVjzDiiV7jZf+vfDcAEswrOmo+tqGT/Wepvqoqv4i cYhFs7yv6GFR+8mAXqv32ILlDeU7ms2x3m2of5ilpliTarV0MptBuRabpbnz5IvqZNfD REIYcjYWp42k6Pf72Sa1055oC8HdIL8tMkPt1d3HWDXVkkxGjarXwM2ARX03IC08R0V2 7KjdcC8Zx9zprkEJOJ909z6Fu+7vutk+rTOwG5k82Hqo9h4i4FAXwIvpzH7Nb4d8rjdm 1AOi42J67iUSm3yILic7W0oz97c4My94/D5+5zDWCn5kVRP0PN/QpILEd1zFyHU3bYsF xeOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=A2tCydh/CLQsBjKQiGDPAQCXvbEKtwUUqZhnhpd2SIM=; b=IpTyT8tgOObUwe9MTGsgcZRZXZpr2lduFccw9eLVYHe43kPM6K9srQCVwLJemMnibt CitvaC389TtG1gqXTCSxY/BQM++j+CDTQAS2PAT3Jmc3dbjaww5s6VqVgaQ/RRyT5ry2 OYNPu1gh9jCvsnwWRy7+ESJnqc8t9g/uQ2kxhG//WqIBawX5I5zgtN576jeeFG/b9yEX 0irEbIODVQ5a9bIvxW1+aGod+0eXOLuWOgmFIjhCPfrh2JkqUF+89ynGcGqILhezlKxP F1gwFSnqfWtdGXPbrdz4ITcvQJdqNQMowd8S1JloUvv5M//5X/Ys/nvlFddfzB2uBlVe 8YEg== X-Gm-Message-State: AIkVDXIqA2/uTpMJUMKQPTD8nBKK7r37tVOk0HFg9PrkDBvz3U9u9m6RKYE0y8s6cEA21g== X-Received: by 10.223.143.48 with SMTP id p45mr4656524wrb.33.1485990365915; Wed, 01 Feb 2017 15:06:05 -0800 (PST) Received: from ?IPv6:2a00:23c4:4bd2:6e00:c58e:52c8:eff:c62b? ([2a00:23c4:4bd2:6e00:c58e:52c8:eff:c62b]) by smtp.googlemail.com with ESMTPSA id w16sm31894288wmd.4.2017.02.01.15.06.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Feb 2017 15:06:04 -0800 (PST) To: internals@lists.php.net References: <1E.BA.51557.966F0985@pb1.pair.com> <20170201160548.7qxyjhlnpfepwmgs@portable-ws> Message-ID: <68e8ffea-7df9-a3e5-23ac-0600c93d5986@gmail.com> Date: Wed, 1 Feb 2017 23:06:04 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: [RFC][Discuss] Arrow Functions From: rowan.collins@gmail.com (Rowan Collins) On 01/02/2017 20:17, Rasmus Lerdorf wrote: > You probably think of $var as being a local scope variable here, > but really it isn't. It is an imported variable that happened to not exist > in the outer scope and it was assigned a value in the inner scope, but that > assignment can't leak back out so it is still unassigned in the outer > scope. I'm very confused by your terminology here. You definitely talk about two distinct scopes, "the inner scope" and "the outer scope", but then you assert that there is no "local scope". Surely the "inner scope" is "local" to the closure? In actual fact, it's local to *each invocation* of the closure, because the function is initialised with the original values each time. For instance: $a = 1; $fn = fn() => ++$a; $a = 42; echo $fn(), ' ', $fn, ' ', $fn(); This echoes 2 2 2, not 2 3 4, because the $a being incremented is new for each invocation. Nor does it echo 43 43 43, because it is only the value of $a that is captured, not its reference. I think the best description is this: the closure has its own scope, which is initialised on each invocation with a copy of another scope taken when it was defined. To go back to Bruce's question, the original statement was: > you don't typically need a local scope at all for these short closures The important point here is that within a single expression there is very little you can meaningfully do with a local scope other than read from it. It's generally a bad idea to alter the value of a variable and expect another part of the same expression to see the new value, because you can't always predict how the compiler will rewrite the expression (I think an example of this came up on the list a while back, but can't think how to search for it). So for most purposes you can consider all the automatically imported variables to be immutable values, which makes their scope much less relevant. Regards, -- Rowan Collins [IMSoP]