Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117941 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15045 invoked from network); 14 Jun 2022 09:30:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jun 2022 09:30:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 093591804D0 for ; Tue, 14 Jun 2022 04:18:09 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 14 Jun 2022 04:18:08 -0700 (PDT) Received: by mail-wm1-f53.google.com with SMTP id r186-20020a1c44c3000000b0039c76434147so693822wma.1 for ; Tue, 14 Jun 2022 04:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T1nfmJfZ9qoMAqFqe6O87qwx2omme8q0SYdnXDfDh6A=; b=qwhL1lrnpAZIzF00ND0MuzaWdZwx5MrN518x770XlkwezWJ0h2O5eE6fjfFj3FGacz 6/GrWU/0++Vl9vJ+2/gyBuV7At0nafL0ewXru6R5wp2oVHToQ/P/7joinaTyaLWCi+zv zQC8uH+v6qDwihPvqhv+ADlR3hHF/QCOTdcl/o6OAGnE2YIthC1Vl8KcqVjcj9WCazWU I+UUqL1sDUnI3k9Fuw12zLBA7D3OvvaaMXxBPm7VD9yzSpSSLknZII7UK/+pVMHENaMr H9hA+46+auAPQlAqnOd8XAewijUT8HgZ6TG5UvDTegweZ9CxSRwgeHraN6Or1+V3cttz 5YZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T1nfmJfZ9qoMAqFqe6O87qwx2omme8q0SYdnXDfDh6A=; b=3nS/MO86QwWPziU2eN1RmbN1vxpPtDlEixUrTUlP+0o65W7lLdvVt9hAEIfJ/y7T2A yGy2vVEDHz4cjUcqnS1a9DDfKAusEEhhgs7QwV5Wqr+yCJ0X5MtM+8laYDacKI9s/hg9 0rg36kCH5JYi6Snf0zf0Z82IK+E1Xjvui8oQXmmjbzRFjqN6GQid/oB33ylXz6CwnBVN h1gsOO4FS57R33rQBbMzSmaIuezZvzL5lH1KiGI4e9NyxEEjHAEPt1rnEw6gwXyGIUZu u0UnuYH7fz6ByL0gUGFzKeNzMuXou4m/lWi/sq7mgkBH22/Zw78/HMBJoBiPszP61rUB V6ew== X-Gm-Message-State: AOAM531CNH97KmitO1ocJbEjBAaR1vEn3Tu706Nm8rdG4vXKgBiFVxgc D7IViN52h2utDfoaWkvAGJ06fwx01drKxQ== X-Google-Smtp-Source: ABdhPJwULy41MJ+tenJg0ITMc4Yx2LrhtUM5uAz7hUueC74KR1ifQGfEgkbC1++1HqGEsY+ChmQ/dw== X-Received: by 2002:a05:600c:3d18:b0:39c:474c:eb with SMTP id bh24-20020a05600c3d1800b0039c474c00ebmr3553423wmb.87.1655205487240; Tue, 14 Jun 2022 04:18:07 -0700 (PDT) Received: from arnaud-t490.localnet (2a01cb04054b5b00e130479cc8d1deb1.ipv6.abo.wanadoo.fr. [2a01:cb04:54b:5b00:e130:479c:c8d1:deb1]) by smtp.gmail.com with ESMTPSA id 84-20020a1c0257000000b0039db31f6372sm1743637wmc.2.2022.06.14.04.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 04:18:06 -0700 (PDT) To: internals@lists.php.net Cc: Rowan Tommins Date: Tue, 14 Jun 2022 13:18:06 +0200 Message-ID: <2680037.BjyWNHgNrj@arnaud-t490> In-Reply-To: <8422e11c-4a3f-9f99-56ce-884491dfe08e@gmail.com> References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <2347345.PIDvDuAF1L@arnaud-t490> <8422e11c-4a3f-9f99-56ce-884491dfe08e@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: arnaud.lb@gmail.com (Arnaud Le Blanc) On lundi 13 juin 2022 15:36:26 CEST Rowan Tommins wrote: > > Auto-capture in PHP is by-value. This makes this impossible. It also makes > > explicit declarations non-necessary and much less useful. > > > > Live-variable analysis is mentioned in as part of implementation details. > > It should not be necessary to understand these details to understand the > > behavior of auto-capture. > > As noted in my other e-mail, by-value capture can still have side > effects, so users may still want to ensure that their code is free of > such side effects. My choice of words in this reply was inaccurate when I said "In these languages it is easy to accidentally override/bind a variable from the parent scope by forgetting a variable declaration.", since "override" can be interpreted in different ways. What I meant here is that it is not possible to accidentally bind a variable on the parent scope. This is actually impossible unless you explicitly capture a variable by-reference. Do you agree with this ? Possible side-effects via object mutations are documented in the "No unintended side-effects" section of the RFC. This assumes that property assignments or method calls to captured objects would be intended, since these assignments/calls would result in an error if the variable was not defined and not captured. Do you have examples where assignments/calls would non- intendedly cause a side effect, with code you would actually write ? > As noted in my other e-mail, by-value capture can still have side > effects, so users may still want to ensure that their code is free of > such side effects. There are two ways for a closure to have a side-effect (already documented in the RFC) : - The closure explicit captures a variable by reference, and bind it - The closure mutates a value accessed through a captured variable. Mutable values include objects and resources, but NOT scalars or arrays (since they are copy-on-write). In the first case, this is entirely explicit. In the second case, the only thing you need do understand is that if you access a variable you did not define, the variable is either undefined or comes from the declaring scope. Accessing undefined variables is an error, so it must come from the declaring scope. Your example uses isset(), which is valid code in most circumstances, but as you said it's not particularly good code. Do you have other examples that come to mind ? > Currently, the only way to do so is to understand the "implementation > details" I'm willing to make changes if that's true, because I definitely don't want this to be the case.