Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114247 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23067 invoked from network); 29 Apr 2021 08:09:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Apr 2021 08:09:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5A3541804D8 for ; Thu, 29 Apr 2021 01:14:37 -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-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 ; Thu, 29 Apr 2021 01:14:37 -0700 (PDT) Received: by mail-wm1-f50.google.com with SMTP id g65so6119526wmg.2 for ; Thu, 29 Apr 2021 01:14:36 -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=avlKfqiiu5bbRJxwAezRWStxIo91PxHppXd5I03bJSE=; b=GudL1ogv0yG+S8OJvU1zhGFuLlKx8QHh7mh6/jaJiNeiBEH1EbQFmkaseMpmK/vZoh 7WnH+01Mqdk/xb1nNDmvfyRe/dpA9nPHbAdAyymwdGSA0VpoGGI+iePEGkX2iWFdFa+7 0fKQ/Xe4iRc83m11bZAWhhdNWknG1k6flWpm8SGax8UEWc/apTLgMHEx5Y4pN1CfX4/K 4jzGDko3ohgPXpb+j2r6FtYdA5GM0tVvRLmX16q6bX3DlBJis8ZbBRNdtvus1MYastVN kDdG69IeiDP7wYuUv/Hl/Fv622QB9ruup/UpIaKERQhTG1JQzxjDbo1EJDH4qCVpPyZc ytkQ== 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=avlKfqiiu5bbRJxwAezRWStxIo91PxHppXd5I03bJSE=; b=gN7OIzJPTey+xdHmHdwZ4eP+0GYND7fCT684ZgNs6ElbWfRN4d/TQizg2SoTUCkuId lf59cYRFm5lIaSDzP5+fdTY2Sd+Zk5felptxSE6NiMxE23rAInstoA2m8CPQ0z7gvF9h LfXW1awVjmglZLwhAbu0UWwssq75stvyNropDdkZw1DH2/fqGWckBQCC6D154EflRrMU ncvxqOIlyVR6DBdgzCovHkM3nxKdGzYsOMpvs/1+Uwo0BKwVUTBaiy/gcSRPYfW9Ju3l viwx0/kkz2Ie8ihH36Ls4ZTesP9hYPnnDq8pBCEyFhvrcMqM9c91X0RZQdk30weQYluM I4Yg== X-Gm-Message-State: AOAM5307wtSs66W/TLxbMUJ4Qwwcd2IfVj9h/Iz6xgLKhgsnOXgEq/zV BJ+q/Kh6zigplr9GsL/jLlbepsXCrQs= X-Google-Smtp-Source: ABdhPJyBkcKRE7LHILIkUxBDLmFe+DIEaCzVHPcry4tmH1bQb7lX2zp8+yby2F2GxBzyH1aJQG4ALw== X-Received: by 2002:a05:600c:21a:: with SMTP id 26mr1761682wmi.44.1619684074308; Thu, 29 Apr 2021 01:14:34 -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 p7sm3473468wrt.24.2021.04.29.01.14.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Apr 2021 01:14:32 -0700 (PDT) To: internals@lists.php.net References: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> Message-ID: Date: Thu, 29 Apr 2021 09:14:29 +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 23:00, Nuno Maduro wrote: > Concerning point 2: Developing some sort of static analysis that can infer > what needs to be captured may be problematic. First, that won't be > consistent with the way auto-capture currently works in PHP (one-line short > closures). The question is, how do we decide which variables are local, and which are captured? Options include: 1) All variables are captured, except those declared local. This is common in other languages, but has no syntax in PHP. 2) All variables are local, except those declared captured. This is what the "use" clause is for in the current "long" closure syntax. 3) All variables are captured, there is no local scope. This is effectively what PHP's single-expression closures use. 4) All variables are captured, unless provably written before read. This is what I think Nikita is suggesting. Option 3 is the easy option, and is currently "good enough" because it's rare to need a purely local variable within a single expression. For a full function body, local variables are much more likely, so we now need to think about the question more carefully. Without a keyword like "var" to declare it, I think most users would assume that an initialisation like "$foo=null;" at the top of their closure would make a variable local. Regards, -- Rowan Tommins [IMSoP]