Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114242 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55370 invoked from network); 28 Apr 2021 16:11:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Apr 2021 16:11:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E1FAF180531 for ; Wed, 28 Apr 2021 09:16:31 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 28 Apr 2021 09:16:31 -0700 (PDT) Received: by mail-ej1-f53.google.com with SMTP id gx5so3395686ejb.11 for ; Wed, 28 Apr 2021 09:16:31 -0700 (PDT) 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:content-language; bh=JL6XEUdWncCAHwjQv9GtdTtWXn2OJD39DtvqJOz1kFc=; b=UQFY+KKxx/3R8KxH4/AZoHglgdrdRCcSjm641K2N+/vFTom+1C0xucFuoZYWvFWB5x zGUgGKk+yA764xvET5mRZeoYTQkYPGfPLZCMoDDuVf3j4LzXpZJx2x99boam618XMVy/ v5HJtcfdgc+mc9IyWVXpDXeV4M9rwUlGxK/22MMHgxO2x4WFocEhyJMYeJiAk1gsD6Fn pJbYEymoipMLIRvJcPPTugOn+9PFa+GIy1tNm9R5y7OOMigQ/IDHway9OC6FWS5wMrty ruCqNlRNZb+TS0FyfkMjX1SlZ2m2szke6aAioy83wTjObdL71HSZAp24KGppnGIhNiJM dT5w== 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 :content-language; bh=JL6XEUdWncCAHwjQv9GtdTtWXn2OJD39DtvqJOz1kFc=; b=l9fWd1ca3vF0W8EpId/n3Ztq6zpteoFxNBDTVSYxOGrCtOkqAHkSGtaUT6+c5Y3xvv F3bLlqxSTOv1WmRQAeNMabTIi4hXV5EiKDcUa49m0wSHYDSufYhQS/LW9O7+vKb/rl7x 3Ikxed5u6ju1nfHBltW6aCxxN6/GzFPhdOFbTnBkbNQZ1MExBK3Rhc2XEB+Emr83DIKQ iCD0Nq7Ve5k/790mAzWjB5KFQIgCTx1ZNXBkviLZf3QDCelCZ0I/Rf4mFU1XqG1BaNZG NkffVaGXFsWK3bShTWGPi8jUTkz4rTSfKnB5oFXXZ37J6QforMvLylk1uKxEXvA1PIZn Z0jA== X-Gm-Message-State: AOAM531XjAmJ8vrLMpI4ixmX+ID/fU2xwqjuTY3vEw3GifCtlybWOQMM VTD/yvoRtL+DbU3al9Q+mOygsDKTPX8= X-Google-Smtp-Source: ABdhPJyuAoQzSqxgy0gp2mak9+kbOXixDFUTNZ4hrt48ETaXUcLPf2WCbK7hd9KtCBnWpplIDfTPEg== X-Received: by 2002:a17:906:590b:: with SMTP id h11mr17630656ejq.147.1619626589118; Wed, 28 Apr 2021 09:16:29 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id p4sm196001ejr.81.2021.04.28.09.16.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Apr 2021 09:16:28 -0700 (PDT) To: internals@lists.php.net References: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> Message-ID: Date: Wed, 28 Apr 2021 17:16:26 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] Auto-capture multi-line closures and short functions take 2 From: rowan.collins@gmail.com (Rowan Tommins) On 28/04/2021 15:31, Nikita Popov wrote: > My suggestion would be to allow use(&$count) on fn(), which allows capturing > certain variables by reference rather than by value. It might be rather confusing for the use block to sometimes mean "capture exactly these variables", and sometimes mean "capture all variables, but modify *how* you capture these ones", based on if it follows "function" or "fn". In other words, it's not obvious at a glance that these two closures have completely different effects, and why: $increment = 1; $count = 0; $a = function() use (&$count) { $count += $increment; } $b = fn() use (&$count) { $count += $increment; } > I think that extensive experience in other programming languages has shown > that auto-capture does not hinder readability of code, and I don't see any > particular reason why the effects in PHP would be different. The difference between PHP and a lot of those other languages is that variables are not imported automatically from other scopes. In PHP, the following global function and closure would not use the same definition of $foo: $foo = 42; function echoFoo { echo $foo; } $echoFoo = fn() { echo $foo; } That's not automatically a bad thing, but it is an extra concern that PHP has which other languages don't. Regards, -- Rowan Tommins [IMSoP]