Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129639 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 311431ADC3C for ; Wed, 17 Dec 2025 18:03:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765994615; bh=a/t28RWzE4rpqd1J2fy5U+qPdP3zFAoFMaWQAubhIRg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=IWB/XcklKP0xGmGzDT/zOw7aP0ENKVoLSyXBGn/x0yqJHKZAIVWWk3ETEu1KQomyx 6Gt66dplcEyJNQMkunqFC/f6yGqFwvXS4ibcCIoeGm2Kti9zmyeSyaBpv+jkA+5jGw ki1WoiuJJA6keG6erXLOiWJA2iYbQnafHOnG4R6mc8HCCG18JEZycqsl2jYp21CmSR Odu4m5g37v63SsL3Nw0JgXhGb6GVGHiE2uz2jqlOWlUi4ox4iXSOxtvvU7m3WNVc1s ibRw8kpYB4dOPz3lmFKOSc+rkA46F53AERql+R13ngIiBbwl5O7/SDMHCddDu5fhVI keiWzqnaNLHEw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7F99C180393 for ; Wed, 17 Dec 2025 18:03:33 +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:03:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1765994605; bh=PAc0GGsNhXlWVNzYSImbQDus36fD7KLE5UCHSKn6gq8=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=Z2n4WDTahy+mCAkv3tevIuo5u2UPp47P7KsUdCQF/hatDLIRJ05IgLlPfOprRa9/d QQ6TPgI0NP1bEgmaC8pR6nP5N6rtiL6NCRNQd3LP37SnJV9d+XR9IUb88hEcnU/qoW Hg8XSlgklRO+iSGUhJEZg/WpzaZ7rStFJWjlhyhqcZ0IHT+dAt6nI9qYVvh9YIcKwY E8zA0xpMZFI+v5b/lnW6UTh41gPtGr/i5N3U+zGs3LE13bBdWtV9Xdt40lhm1E2xQd 0zFm4KnH5VgUUph1ZyukG6yTKE7f2tOWzTwkN7Mu4vEe0AuYoDbHjvDDBB2HbZp/BQ C/sSL3TJprDvw== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 17 Dec 2025 19:03:25 +0100 To: Pierre Joye Cc: Larry Garfield , 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: <2831b7be21b21f4d98ef41d67a23b40a@bastelstu.be> 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-13 04:18, schrieb Pierre Joye: > My primary concern with the suggestions of integrating let into > existing control structures (if (let $x=stuff(); ...), for (let $i = > 0; ...)) is ambiguity. The same for sequence-like syntax proposed > earlier. PHP doesn't currently have block scoping, and introducing it > in a way that reuses or resembles existing syntax patterns will be > difficult to distinguish from current behavior. This could create Yes, this is a big part of the reason we've chosen the current syntax with its dedicated construct that also forces all block-scoped variables to be defined together at the start of their respective scope. > hidden bugs that could be hard to catch. Without talking about > changing let to "semi" reserved word. Not sure what that means tho'. > :) `let()` being a semi-reserved keyword means that it will become unavailable for use as a free-standing function, since `let($foo = 1);` would be ambiguous otherwise, but it will remain available as a method name, since the `->` makes it clear that it must be a method call. > The 'using' syntax proposed earlier in this thread, mapping maybe the > 'with' behavior may also provide such an unambiguous definition. Sorry, I'm afraid I don't understand what you mean by “mapping the 'with' behavior”. > I am also wondering about the actual need of having a block only > scope, and potentially for some variables only (if that's part of the > behaviors as well). When a scope is needed but one does not want to > define a separate function, closure and co are cheap now. But I may > miss some obvious benefits that could benefit from such additions. Perhaps the new “Example showing memory-efficient batch processing” example (added yesterday) is making a good case? The alternatives there would be `unset()` or a function/Closure which then come with the boilerplate of passing along all variables that are required for the scaling logic to the function scope. I find having the logic inline to be pretty natural in that example. > That would be a great addition to the RFC, actual use cases and > benefits over alternative existing ways to do it. Almost all other > languages provide block scoping, except bash (nice friend here ;), but > it does not mean we have to go that way. If we do, I emphasize again, > it needs to be extremely explicit. The “Examples” section is starting with examples that show the feature in isolation to make the semantics clear, but the later examples are intended to be representative of real-world use-cases where we would've liked to have block scoping in the past. Do you wish to see more explicit comparisons there? Perhaps you have another use case to add? > PS: If we were back to php2/3, heh, even 4, I would propose to simply > introduce block scoping in full, that would have been a more standard > approach. But time flies, and we are at php 8 and it is tricky to > introduce this at this stage :) Yes, that is also what the RFC tried to say in the “Design Choices” section (and also in my replies to Rowan). We are adding block scoping to a language after the fact and thus different design considerations apply compared to a language where block scoping is an integral part of the language semantics. Best regards Tim Düsterhus