Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98111 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19036 invoked from network); 1 Feb 2017 20:18:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2017 20:18:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain lerdorf.com designates 209.85.218.50 as permitted sender) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.218.50 mail-oi0-f50.google.com Received: from [209.85.218.50] ([209.85.218.50:36038] helo=mail-oi0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/26-51557-2A242985 for ; Wed, 01 Feb 2017 15:18:43 -0500 Received: by mail-oi0-f50.google.com with SMTP id u143so240574146oif.3 for ; Wed, 01 Feb 2017 12:18:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lerdorf-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=xtTmZSmvabzlyl0Cy69iBvoYXTEU0ipbNqlqdzTggis=; b=h7ff8O7OIwvYJ6qO45UnGGetzuf79z+0RfFCG4YQL8EQDBHeMZwkTmTRePzJ3n6cgq d0YsVUr0A8/zYzumDTbDacjvCv/aXvv/k6pksGd9tBBhSZQS2nrOfxuwn2JWjWQC9Olz 1Zls6Ibp7j3zUj/yTD2OEW+s2B8uuGWyW05QkBaCiF6mAiWc6muaGsACzKatjvv7f3e3 N7QzzXMm4wwJ9krzz7ENqdBBlTOFXvTkQT5+MLYpPFFlnlRkAlOCd2Eqxqv1YhaZQxmE /P5p/4aPrLIdVrBu5DKj686DRZ/hnMq9YO385jMKzC1ryi64SNzRzVXCDc/MJoNLorm+ Y5ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=xtTmZSmvabzlyl0Cy69iBvoYXTEU0ipbNqlqdzTggis=; b=fRf0ma5gHay7UAQxTpmK3Jkza5A7d8mMzwKn+gsmdDOKjZC6rRgjxk9PuhRxdWBuKv AaH6DMCqM7RxpBcjXKplVVyCD3MnPwcWdZ/YhcGqRDg6dktnTPjR280/+Aiacl6sZ4Tj 8avnaCFYE4WlM603xODZhCnNdAszqbrvbvUUhgc7wY+hkN8NDZYMdxsBO2Dm1dzE+TXt Gy6PYBf9Pr8L7tnGrEbghBU5/dkNVLCBhf+oZ1/NdPeRq+GZDsjv7TJuG4W1MzCtw3yt r3Z5VVh/UiNR/UrDxWJaZ6rfQNM/7pwXtuanhv3v+XQtPyeO6JSePYKJmhbyAFpn5kHY OV5A== X-Gm-Message-State: AIkVDXINt3gKKC0uGA9uFxQ5UmCJmUtTNih96NvxrVSyPeakl+NqogAs6XPs0vL+4Nc1mEmnkRUks9Irci0lCw== X-Received: by 10.202.79.151 with SMTP id d145mr2362279oib.159.1485980320398; Wed, 01 Feb 2017 12:18:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.121.84 with HTTP; Wed, 1 Feb 2017 12:17:59 -0800 (PST) In-Reply-To: <20170201160548.7qxyjhlnpfepwmgs@portable-ws> References: <1E.BA.51557.966F0985@pb1.pair.com> <20170201160548.7qxyjhlnpfepwmgs@portable-ws> Date: Wed, 1 Feb 2017 12:17:59 -0800 Message-ID: To: Bruce Weirdan Cc: PHP internals Content-Type: multipart/alternative; boundary=001a113d6b7a2413b605477dc112 Subject: Re: [PHP-DEV] Re: [RFC][Discuss] Arrow Functions From: rasmus@lerdorf.com (Rasmus Lerdorf) --001a113d6b7a2413b605477dc112 Content-Type: text/plain; charset=UTF-8 On Wed, Feb 1, 2017 at 8:05 AM, Bruce Weirdan wrote: > On Wed, Feb 01, 2017 at 07:45:50AM -0800, Rasmus Lerdorf wrote: > > The reason it is feasible to do this for single-expression closures in > this > > short form syntax is that you don't typically need a local scope at all > for > > these short closures and the syntax doesn't convey the idea that you > would > > have a local scope. > > Does this mean, in the context of this RFC, that short-form lambdas > won't have their own scope though? I think it's not clear from RFC. > > Example: > // would this create $ret in the outer scope assuming $ret was not > // defined > array_map(fn($elt) => $ret[] = $elt, [1]); > var_dump($ret); // NULL or array(1) ? > > Current implementation (available on 3v4l.org) does create a local > scope, but it should probably be explicitly stated in the RFC (and > docs, should the RFC get accepted). > I actually tend to think of these short-form lambdas as not having a local scope. That might sound a bit odd, but let me demonstrate: $f = fn() => print($var=1); $f(); echo $var; This should output 1 and then give a notice about $var being undefined on the echo. 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 think of it this way, because if you do: $var = 3; $f = fn() => print(++$var); $f(); echo $var; You should see: 43 $var did not originate in the inner scope, it was imported from the outer scope by-value and reassigned. To me, automatic import precludes the notion of a local scope entirely. When a variable you use within the lambda isn't defined in the outer scope it acts exactly like a locally scoped variable, but it isn't, because defining it in the outer scope could potentially affect it depending on how it is used within the lambda. -Rasmus --001a113d6b7a2413b605477dc112--