Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116352 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11435 invoked from network); 14 Nov 2021 20:32:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Nov 2021 20:32:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1D543180384 for ; Sun, 14 Nov 2021 13:26:37 -0800 (PST) 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.2 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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 ; Sun, 14 Nov 2021 13:26:36 -0800 (PST) Received: by mail-wr1-f41.google.com with SMTP id u1so26618076wru.13 for ; Sun, 14 Nov 2021 13:26:36 -0800 (PST) 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=Rz6a8O73YcSGTTUEwB9RV83wYNWoWSWi2aXfFuJ11XU=; b=ohbNIFelVMXGDLVET1ySsKRJ+sdG7If94SaYvbPQytaJkAq2vpCGDhmkPj8FV7ZHJU AM0kLu0euCnnNbxNbjYZyRhi1UByJ4m9Dv0fOhx84orX0alRXfz9KsqLx2kqU3hw3iws ddIzeafNUqM6VAKX7ILgjArKh7j06BCjFwr1CwtJHE4vFgx2QUuPEqReg2jFaRU3fouG Ub0weCP+dPbbj/Oq6EFe1r7zIpCmbYKyme00UCLz8+JbPT1sAdHuMCRK+2g9OgobnDd5 mdg7n6PGCse/D43rn34LzDWCe9ovNYvdN9bb8PygLDPHoc/+fuzinrlAW7+Y8j8WUrki Qe6Q== 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=Rz6a8O73YcSGTTUEwB9RV83wYNWoWSWi2aXfFuJ11XU=; b=1eRIyfc65v9WzCFl4VBWks0pEKEMxvuMis5j7fMV2+hi/OSEC4xX7rhpeSewt9knB3 hKaEkGQ/hzosYLkYeESUq9s64lmWq9FD7qXo/hszbmWbsEllqWWIjhJLj1ka7w8oM3fj 2PL6ZwEhn2BVOAn06QJQ1sE12PrrZvAHGC3yDjGeU5W0HUF7rsTNP479DUReqUoKFQ8Z dVo4HNVVVzT9LIH6g6E6jKknFpArGci59qHN3w1pYF3NDOpgS7nPBbz7ucJzzrPuosha 1wU6TmGifsoxE6pWIc7QXzURnUrJzsaFtJyamJd7rQJjlBgkP9u6XMjhXelGvUsNZgNz HOfQ== X-Gm-Message-State: AOAM532WXMjabL7DktU7kBc7NJotaI7UUhBjbdisulquOybtENH1S3LX 9mIIrGIOZ4q23ClWsRO+SKxWETSnRAF5Kw== X-Google-Smtp-Source: ABdhPJxIkQY7oCpyHdZCV7+ZgotRZae7FGYz2ScJ9hSYBsaIPiHfhr/JXceQTDVzvEvsEJUFQK0mVA== X-Received: by 2002:a5d:508d:: with SMTP id a13mr40350321wrt.41.1636925195422; Sun, 14 Nov 2021 13:26:35 -0800 (PST) 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 h27sm19679597wmc.43.2021.11.14.13.26.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 Nov 2021 13:26:34 -0800 (PST) Message-ID: <4a61a5d2-e420-86c3-db8b-da23d2c17bcf@gmail.com> Date: Sun, 14 Nov 2021 21:26:34 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Content-Language: en-GB To: internals@lists.php.net References: <71116B29-FA48-4216-BD62-6D49AD20F342@chilliet.eu> In-Reply-To: <71116B29-FA48-4216-BD62-6D49AD20F342@chilliet.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Re: Unwrap reference after foreach From: rowan.collins@gmail.com (Rowan Tommins) On 14/11/2021 19:49, Côme Chilliet wrote: > Le 14 novembre 2021 18:13:18 GMT+01:00, Nikita Popov a écrit : >> I have ultimately decided to withdraw this proposal. > This is sad to hear, because this is a really big footgun, which has hit me in the past. I ended up adding a codestyle rule forcing byref foreach to be followed by an unset to avoid this. > > I understand making a special case for one syntax and not the other is unsatisfying but I was hoping for an other outcome. I think I agree with both of you - I agree that this is a problem worth solving, but also that the proposed solution isn't quite the right one. For one thing, it's just too "magic": although the current behaviour is *surprising*, it's actually a consequence of very straight-forward language rules; the proposed solution introduced a special case that isn't particular easy to explain, with extra edge cases to watch out for. One alternative solution would be to introduce block-scoped variables, which most of the time is what people want (and expect) in *any* foreach loop. Then the special-case for by-ref unsetting goes away, e.g.: foreach ( $array as let $x ) {     var_dump($x); } var_dump($x); //null / undefined foreach ( $array as let &$x ) { // or "&let $x"?     $x++; } var_dump($x); //null / undefined, not a reference Regards, -- Rowan Tommins [IMSoP]