Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113818 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 59236 invoked from network); 27 Mar 2021 19:37:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Mar 2021 19:37:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C3AB91804D0 for ; Sat, 27 Mar 2021 12:33:59 -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_H2,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-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 ; Sat, 27 Mar 2021 12:33:59 -0700 (PDT) Received: by mail-ej1-f47.google.com with SMTP id u9so13388477ejj.7 for ; Sat, 27 Mar 2021 12:33:59 -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=x27+YQ2fxAssfQ8eVBdQuWlhHh/TLfdYRkbX8DRT+IQ=; b=UF0JWdHjdyJ0bHcA3O+spyJLYchXNC3h2mTeAM5czuNzebozxDEr2s1//OTnNGk/Jn d0m+ZgXBh0NSspMFdSCHKyHEppt4cNMWIBrInyydtSnzxf3/VYLFH7ByL+b2xcqYIK4+ nyDMJzUiNWKIUjwIfQOVrueXzd2tFGBknZXvj+5ZsAPgOlFXeBSbRr6sfV7t26YR7V1W vgq++0SrV2NnoKNZ5SZIlgxbX/iOfl36VAWmYF3PnEORrV1swJ5OScVpQZaj7YdvFU81 sq9LWVFqVqorq7hhe5h7vLLRgM6nmjwPUhZ53PSois6kdyTKnn8mUOPhFyL0KaG6HaVH PMug== 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=x27+YQ2fxAssfQ8eVBdQuWlhHh/TLfdYRkbX8DRT+IQ=; b=LYFsLKcUBtTjjlhSbXHP9vml8rHiO3+8GNRBdsigu/PqK6Bmt7DXBY2SkrD3XOhvLm yE15hWViJuIKDK595wda3t9Zb86/300t99HqBTKHVhuDEPhTivyVijyWteABfeuOpDYC 88DdOLb61X5R6JyG0l2ndD0aCfAgS8p9sObc2wDvKwkmmh6gjox9KvJ18ZhYCEnr1GJE i1BsGa9WYAOC/soJ8UUQ6kFrG0/tCwtpY7Gc23Y3qHY5vciKdGi5bykeGyBjo81mxGcX IbKtky2Ixe9/eN7cvC7e1SjqDFCtprNdlwwIwOClKjURtmppvntNDDcdSPwyuhi9d5yg cKbg== X-Gm-Message-State: AOAM531sJepu2u7J9pEptGhY3yllRZKxBAirLLJF5b5cOCz8gEpmsDyO BamhC/+aknfy2ojeso5G9l87cIFuwgI= X-Google-Smtp-Source: ABdhPJxdJ3cgs9OkXXJUYzmgxrSdKR8BrjEXeN79DorjwMyTHz2y0aVYwy6QiFpNl2jpougfQ1H7aw== X-Received: by 2002:a17:906:cd12:: with SMTP id oz18mr21668455ejb.498.1616873636457; Sat, 27 Mar 2021 12:33:56 -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 h15sm6206547edb.74.2021.03.27.12.33.55 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 27 Mar 2021 12:33:55 -0700 (PDT) To: internals@lists.php.net References: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> <635DD146-FC6F-4991-8D2C-5A6B492722D5@newclarity.net> <734f12de-da98-6b76-c2fe-8682f4d177aa@gmail.com> <36E45DD6-E2BD-4801-BAAE-4355C83D1AC3@newclarity.net> <15AE4315-A456-4ED8-990A-49EBD76C5B46@newclarity.net> <5501FE70-FBED-47EB-8010-173644BC064F@newclarity.net> <3d453ce7-db16-fb75-91b4-9a2a71994164@gmail.com> <4932d1da-1f5e-4210-a2ea-a158595519c6@www.fastmail.com> Message-ID: <4d1e84cd-4681-11f3-cda0-9361b57bb0a0@gmail.com> Date: Sat, 27 Mar 2021 19:33:54 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <4932d1da-1f5e-4210-a2ea-a158595519c6@www.fastmail.com> 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 shortfunctions take 2 From: rowan.collins@gmail.com (Rowan Tommins) On 27/03/2021 16:52, Larry Garfield wrote: > It's a valid point that auto-capture on multi-line function makes the potential for unexpected behavior higher than with a single-line function, simply by virtue of there being more lines of code that could do so. It's not just about number of lines, but style of code: the vast majority of single-expression closures will have zero local variables, so the potential for accidentally capturing a variable of the same name is also zero. You're right that it's subjective whether this risk is too high, though. I was partly trying to understand what the risk is with the proposed behaviour, and also considering whether we can reduce that risk by changing the implementation to capture fewer variables. This did come up in some of the previous discussions. For instance, during the discussion of the successful RFC two years ago, Nikita wrote [ https://externals.io/message/104693#104738 ]: > On the other hand, allowing a block body for the closure does add a number > of complications to this proposal: > [...] > 3. Determining bound variables. For single-expression closures we can get > away with binding all variables that are used inside the closure. Writing > something like fn() $a = $b might cause an unnecessary binding of $a, but > it's also a very contrived situation. For block closures performing > assignments inside the closure will be much more common and will need some > more consideration to avoid unnecessary bindings. Regards, -- Rowan Tommins [IMSoP]