Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129640 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 0B21A1ADF6E for ; Wed, 17 Dec 2025 18:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765994654; bh=6O8dbu4O5vBSmdDvI4rcwcKXHVbmsvt0R7B76A0FmxQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TTK8D7OGbKU7+8Rzv2G/VPGoQ1f9rydXQsfPquV61ZpDjkXM831l/mTmLkzQCemXC A+IoVaKuisu/AR8iaNoZM9DBRf80JiDOj2H/p6vsXI2gy2ihNBdOunZ7h5q2IvB4Be UAY3VxojafDWYM0K5YQf5h9vGtzrEXRRLRGqFqTMZtD6mHtz6DSdKNkapF0RzQFgsE y7kLCT1zJhYzgX8yp/yRUaAtyoil22i7VEwbt0/u1ZJIH5YTvztyz/8f25ZBWSM2m7 ZrfpGT4RGQqDfQRJOdKloqXXpF+BzPPoPkIZI3kmW+1DXGILoCYqXw8BcJKW+wKi8M a6lfZEwD+9lgQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0B5BE1804A7 for ; Wed, 17 Dec 2025 18:04:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 17 Dec 2025 18:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1765994645; bh=g9BFKmUIdio8LGnmHVnhgEXidp4AiJB/QJm8lUz1dxI=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=Gh68lonTQP1RpXxuvHctdMyQmunUTgMzxPhRxkB43BtE0oMwIqzA1XZ+RV3xxhNM9 Gsb0eEcYFT61ds0Hjt6sr/yRs+E1dYVPGPKcygXYRxnY+XRuATP0wfhRQyQPiqH2R+ 1j/x5dT2ohruYxYaSH+g7beUpMet4QfMUhmkYZ2yTpjWiezIW9vLeXqPNOaEHt/RlR IEuo0GlfWL447hcMbdxJRqrcxv4MHfdu5WP4ebJmyqisdSR6gS+ScEUPLX8ONAXDxR inQjG1uBOX82wZ7/pq+mmM1L+xVRrcurcSeTxsZEeMMijOHKTeMeJsEWkRzNOdBcMw mieGgrrJobwfQ== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 17 Dec 2025 19:04:05 +0100 To: Larry Garfield Cc: php internals Subject: Re: [PHP-DEV] [RFC][Discussion] use construct (Block Scoping) In-Reply-To: References: <1F3473C7-5D83-48D3-964E-A63D6F44D21E@rwec.co.uk> <4998b4c6-0474-4f0c-b63a-9909b8acfa96@bastelstu.be> <018421f64342a0d960589b4c8eea5cc5@bastelstu.be> <84b9dc16-3eb3-4283-b015-3af29fc0e55d@rwec.co.uk> <590fa655-d170-43f2-984c-d0a5ff6c30e4@bastelstu.be> <7c623161-cde3-4fc0-944c-ddfc2785c845@rwec.co.uk> <21f12343-b212-456f-93b3-079810d3d76d@rwec.co.uk> Message-ID: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-12-12 22:54, schrieb Larry Garfield: > The more I think on this, the more I think that the auto-unsetting > behavior of a `let` would be useful *only* in combination with some > other existing block, not as its own block. We very strongly disagree on this. Arbitrary block scoped variables outside of control structures have proven their value in other programming languages and the same use cases also apply to the use in PHP. > if (let $x=stuff(); $x < 1) { ... } > > for (let $i = 0; $i < 10; $i++) { ... } > > foreach (let $arr as $k =>v) { ... } (applies to both $k and $v) > > And so on. (I'm not sure if it makes sense on a while? Possibly.) > Exact syntax above is just spitballing. It does make sense on a while: let ($row) while ($row = $statement->fetch()) { // … } > But that would allow for the mask/unset logic for variables that have > special meaning in existing block constructs, which is generally what > you'd be interested in. I don't think there's a huge use case for > unsetting arbitrary variables in arbitrary places. It would also be > cleaner than the current pattern of if ($x = stuff() && $x < 1) {}, > which always felt clunky and "leaks" $x. > > If you need some thing more arbitrary and custom than cleaning up an > existing block construct, then the additional setup of a Context > Manager is fully justified, and more robust. We have added a new example use-case “Example showing memory-efficient batch processing” to the RFC that shows the value of stand-alone block scoping for a case where the goal is the unsetting and freeing of memory and not the side-effect of calling `__destruct()`. Somehow attempting to merge the block declaration of `$scaled` into the `foreach()` probably not going to be particularly readable. Limiting block scoping to control structure initializers blocks some use-cases and does not provide a meaningful (syntactical) value-add over the dedicated construct that composes with the existing control structures. Best regards Tim Düsterhus