Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117940 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10494 invoked from network); 14 Jun 2022 08:41:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jun 2022 08:41:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 86831180212 for ; Tue, 14 Jun 2022 03:29:12 -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-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 03:29:12 -0700 (PDT) Received: by mail-wm1-f43.google.com with SMTP id c130-20020a1c3588000000b0039c6fd897b4so2927816wma.4 for ; Tue, 14 Jun 2022 03:29:12 -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=BeJc6h+AqMgPFy1lgaTA1PiXQ7R8LrW7AiM5R9eC8ak=; b=Fxe/nlx6D7ztvgVOoB2SM15GYiACrqfFxCQF7MZZmkM/OhqjXxWiZTGgUuN8Et372O 6hUezV2ZNJw1oGHChr76WU/5Aj2e3ur3CpkUNO0+kcgd+0IUiDwxf1Q7DUeK2Guvm7ju UnZy4JiELqCUeSxa5XqCZKJWLoHyEYnYZklkU+sV8vOLE4Jpb4bBTgnLtbEm1XDo7XWM 9kocqriPm807OMyyjBEAFbuoBc1xrNE0sOFlqp5YNRecINwXX+v8nv4qedto+qSqYoxK 1p5rSv1l5Vg1DArW3dBwNdcunW7hfg/7iheCZxRpEK8897rvcjGOxq5Kz7eOTbNNTX54 CAQg== 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=BeJc6h+AqMgPFy1lgaTA1PiXQ7R8LrW7AiM5R9eC8ak=; b=U619HihysFRf5kwE7rF6ZYOzQZJM34LE1QKOQ79I8mXntPdAHJvlGJBOhOOcxKhJ+p ho6vt1Kjv0kuHi3Ztfbl7pvrEmRXonXOwi5N5KVcJ763ywNFQweMCKq6Y0ioClgQSF9F +KrNZWDc/AHn6PqKMRbv2wIw84QWLP2POjN1d0oUuaGDvigDMJvmmRQuaU5eOLq/QsqW 2v8ZxfI3+hyG41K0CFlsm+wcplJ4lBz+4oCpZRqqhvwfy0zaA4lnHqkf5K8ONN85eZja LPQtCgJBQ4E5CQCx2P0Vvvlug9ncYCx5EBG3XDPyTK4xjrMWr3QGkJcAK4YsoqTqAOR2 5ZJw== X-Gm-Message-State: AOAM533XV9kjYm/RWRjPXcODDA/slLRxRmR5MMAk8bfkM02HPHxeE84R 31lEkVRaKSRlt5+XPDpJePfAD/alKH0sDA== X-Google-Smtp-Source: ABdhPJxdbvsx5ndR72glj4AlwOkCRzFf/5pV9QEpwLwSErvse4+1jmefpDhkTUTu+cGROjE2ISVY7A== X-Received: by 2002:a05:600c:1da4:b0:39c:8ca8:5f1d with SMTP id p36-20020a05600c1da400b0039c8ca85f1dmr3321767wms.138.1655202550746; Tue, 14 Jun 2022 03:29:10 -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 p2-20020a05600c358200b0039c8d181ac6sm2481383wmq.26.2022.06.14.03.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 03:29:10 -0700 (PDT) To: Larry Garfield , Dan Ackroyd Cc: internals@lists.php.net Date: Tue, 14 Jun 2022 12:29:09 +0200 Message-ID: <11078866.5MRjnR8RnV@arnaud-t490> In-Reply-To: References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <2347345.PIDvDuAF1L@arnaud-t490> 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) Hi Dan, On lundi 13 juin 2022 19:49:10 CEST Dan Ackroyd wrote: > > Auto-capture in PHP is by-value. This makes this impossible. It also makes > > explicit declarations non-necessary and much less useful. > > Separating off some pedantism from the hopefully constructive comment, > > I think some of the words in the RFC are a bit inaccurate: > > A by-value capture means that it is not possible to modify any variables > > from the outer scope: > > > > Because variables are bound by-value, the confusing behaviors often > > associated with closures do not exist. > > > > Because variables are captured by-value, Short Closures can not have > > unintended side effects. > Those statements are true for scalar values. They are not true for objects: This is shown in the "No unintended side-effects" section of the RFC. I agree that the choice of words is inaccurate, as "modify any variable" could be interpreted not only as "bind a variable", but also as "mutate a value". The section you have quoted is meant to show how by-value capture, which is the default capture mode in all PHP closures, is less error prone than by- variable/by-reference capture, by a huge margin. Especially since variable bindings do not have side-effects unless a variable was explicitly captured by-reference. Do you agree with this ? The "No unintended side-effects" section assumes that property assignments to captured variables are intended side-effects. In your example, the programmer intended to have a side effect because `$a` can only come from the declaring scope (the code would result in an error otherwise) : > $a = new Foo('bar'); > $f = fn() { > $a->value = 'explicit scope is nice'; > }; Do you have an example where the intent would be less obvious ? With code you would actually write ? Cheers, -- Arnaud Le Blanc