Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117945 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36474 invoked from network); 14 Jun 2022 13:57:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jun 2022 13:57:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7AC8118054D for ; Tue, 14 Jun 2022 08:45:27 -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, 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-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 08:45:27 -0700 (PDT) Received: by mail-wr1-f49.google.com with SMTP id o16so11850554wra.4 for ; Tue, 14 Jun 2022 08:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=8AiYvmq/lDEV9D7huX2MAC43TV/FLuaoWT4DhXoAd/w=; b=oJ8p1EegiomNTwaVMKQZpfUk7Oh1MhwRg0XJXBxzs7X0X58i2oK+NId0kaUaDuurKZ Cv5IpkWMhc6pwDWIZTEUcmdXXKArWmclzg7Qmi9J6kiYw/u1nrj29dq5K11Te9E47RAX MRYUUwo1pjjaJB/Z1QfbdrkZSVBcNrt0wFZWI6keemPBTiNYKhQE775TXL5Ip63EMrlf rVH4zr+5QxnGZEnM+Npz1hurGXb4JhVkGzck1vWRalgMX8d3lJndImwMzws+S9wq04xt HPV8cN7znfUhTSIaAnMQ00mVeOGC6h6wW5KZKMrcJQOvAEAbda7UR9DIqaNFbpjKUPGc ViPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=8AiYvmq/lDEV9D7huX2MAC43TV/FLuaoWT4DhXoAd/w=; b=YtdqpSxk3MEAiVY5GZBujkO2ktRFENiNCF6KJzvFg/aqGL1JnLwe7x1j18OLQiaYiX O5x+nPtdxRw28KQRp/WNWWrZLaeEvGxjQAYwGVXt5x8qb1281m5qwxTPXbh54E6BQXos P+t7rC1x/9oRMsIreTK6ov02TxsSeIlEfy69th4AMxrNFN+hSNKIowu2isFHysxzXIAK Ctbe5FX+ElZaBzJI9YAryiX3IR6DIr0dS4+giNuc9DpTWNpvffbaibyhWazMmOods3Zv r+ITrI1Ibz0ma0P1fEYt68vc12W6UY5jZdKqLe1/b5t5xCrUBzXAVQXS/jrn5fd/Z7E7 clWA== X-Gm-Message-State: AJIora/0aiECJ79yy3YHpZlJ0GlWgxaiSyp3WMd2hwUwAGyfMbvxpjT1 994Y6Q7iSfzqd9pPYZIyBqclHfizKVg= X-Google-Smtp-Source: AGRyM1vZSsxfjl6/uTo7LOR6BC+15KzGop1tt0w/GVJsozWRanRb+YsQnB76wS9sgfRaz0M7LkU7fQ== X-Received: by 2002:adf:e944:0:b0:210:30cf:6e42 with SMTP id m4-20020adfe944000000b0021030cf6e42mr5494684wrn.258.1655221526086; Tue, 14 Jun 2022 08:45:26 -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 m127-20020a1ca385000000b0039c95b31e66sm6740447wme.31.2022.06.14.08.45.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jun 2022 08:45:25 -0700 (PDT) Message-ID: <77a5ad8f-7438-8b50-dd9a-f98aee1ac03c@gmail.com> Date: Tue, 14 Jun 2022 16:45:23 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-GB To: internals@lists.php.net References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <2347345.PIDvDuAF1L@arnaud-t490> <8422e11c-4a3f-9f99-56ce-884491dfe08e@gmail.com> <2680037.BjyWNHgNrj@arnaud-t490> In-Reply-To: <2680037.BjyWNHgNrj@arnaud-t490> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: rowan.collins@gmail.com (Rowan Tommins) On 14/06/2022 12:18, Arnaud Le Blanc wrote: > - 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). It's not something that is used very often, so is often forgotten or ignored, but there is technically an edge case where arrays are mutable: they can contain references, and the references remain "live" even when the array itself is passed by value. So although unlikely, it is possible for a by-value closure to over-write variables in other scopes: https://3v4l.org/dPZlI // plain variable $a = 42; // array containing a reference $b = [     'a' => &$a ]; // capture the array by-value $f = function() use($b) {     // update the reference from inside the closure     $b['a'] = 69; }; // call it $f(); // observe that both the array and the plain variable now have the new value var_dump($a, $b); -- Rowan Tommins [IMSoP]