Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129600 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 331B21A00BC for ; Sat, 13 Dec 2025 03:19:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765595957; bh=QsU9/UdOHq82cvjAv8O+dUl7bWEVs6KvDdXhGbuGrCE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Bd5Lp6zvHiq2eK1uH36tRSYMTlZQXSCROiOEWqcpliOGp5dZhbg08Nz6oPwAT9EIX 0lmUPz6F+8dKrC9LCiM6CCwlWBBjUcir5pBNtjUiY9oJp8akoYBkU14VBUE3zvKnwk KvmDLmh6e7qM652JFiq2YNqKIy0bJWoBS7n5EXEoj4MU43CwnmnW4QoiT2DRbReUQO 2i6eA4BpYyebFz5fYoqiuimn9cyIr+9SUSkTJIj97wOMf/9AFw47r2tN0FlikpT5Bj idJFkoaX98QOy49RsD9A6WAQ1m8ar9jBUP+A80iYiAlZdABsHmE/Qb5BtkGhV75eV9 RPKML/vivz3Sw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C6AC3180057 for ; Sat, 13 Dec 2025 03:19: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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 ; Sat, 13 Dec 2025 03:19:00 +0000 (UTC) Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-656d9230ceaso659396eaf.2 for ; Fri, 12 Dec 2025 19:18:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765595935; x=1766200735; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1fxBnynvE2b6NM3AQj0CAuXj5zi6zFEn0SmiaxHWoHE=; b=fWlPbhTuBtjHze7O4GVUTGq9eGY4a5pAIu2hf0bpcSQndZHuyakAvLDrj886BNl6do 5B/5RQXd+o5e6djAr3l+bW2QsFbdeSr5a0NLXAG8Het/JzMs5z8xrFAOG8ijcKE+c4Uk sipKTUEX8RdVDBGSxz6eSBosXRtcbCKjsYXxd9++99toA2726gmWlq/L6JLsEHptYhax okJsSYc+avqTSdW0husRdn13YIZE+qXvrD1hmRkvFVF63SpYVdiMV++NMNG/FeAca0ox 66ddxkoveRnTivxboeO9JzxM81t5TRJ91Kg/qH/KnzF12EOLmY0zQBPwHD3TmeT5VUOD OCEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765595935; x=1766200735; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1fxBnynvE2b6NM3AQj0CAuXj5zi6zFEn0SmiaxHWoHE=; b=bSF2JJAi4KCFr7IvJ6ktnA37JTphCxhJiA0xz6WndMX+ZYozEOzr0P+VBrTc3xJgWO 24RszHp+V8uxbQ0jPQxgM4AiUSY5QWF9cZhfa2BnVScBTrDJpMqOMAC16ewwNwk7qFoP oNzlkeA6t8SgpYaQlU/PIw8dM2Nx0bBzwWcRdOEm6UYSizASC23ZCbGBaj3a/cUFDL94 lUoap8V10Wg4ZjRHka1dCvgzdo314wZknK4/t2UPxtrMkM5ENZ2cQ1oFOWiNQPKrBxRM T8fj6n/J03HDg3HK/QVmxvhddONObf+RwYW3tG/zrHvQ1r49yQ5jCKwN6m6VO2l4Atw1 UwOQ== X-Gm-Message-State: AOJu0YzJRseIC3/eDJhkiy3Vs1bCmNjclj80SieRM3ZYF62gcrrAx6oR IbyfBbi3LT4pwrV8C5g9RQGtDgBoG3D8Qxk7xRQT+ziA3Qi2dKoSOePXzECUcQ2rf45HWTn/VWw waQKbk1nYZgAYfuFHtIkmuchUN7ZaSqW5KfNA X-Gm-Gg: AY/fxX4OvjLTd5M1uasa+Swqq0g/tlViD2IeAnAkOHft1OQkxJG9dOs4hmr8R6SkeId EepCRC5p/y8SWIXi7rdIsOPOutGuqLNWFHjeOiBKXJx08lHtgCY/0OZ+p4yMJr6i2/MWnFKO2at DOfx6Jjma46m6QW5wVttODBpgp/SAtehyblU4eGlhUON9gKsQS3edUeRnuD3bgEdAwJjgL+nTua yutYL4HmaraAmu8Mv3R+8YHiWRyjCC1ciqWZdrS6e5iOMw5/IpcyEAurmgvNoCfSFkt+JNloA== X-Google-Smtp-Source: AGHT+IGERb+UsQ13B4RSrQ35gF88DaAqsju+UVp+cbn2JZr5jSgQ/GIA/i4hscD9sqRbpbwTjSN0VPR9y3JdJki5mxY= X-Received: by 2002:a4a:e911:0:b0:657:5eae:d2e6 with SMTP id 006d021491bc7-65b450ea91emr1883994eaf.8.1765595934778; Fri, 12 Dec 2025 19:18:54 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 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> In-Reply-To: Date: Sat, 13 Dec 2025 10:18:43 +0700 X-Gm-Features: AQt7F2qyEZuC51UkYzd16MaJPCvy18ANQOeBr4GuNRt72FKYU1eYa2bDZBXm-AA Message-ID: Subject: Re: [PHP-DEV] [RFC][Discussion] use construct (Block Scoping) To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: pierre.php@gmail.com (Pierre Joye) Hello, On Sat, Dec 13, 2025 at 6:10=E2=80=AFAM Larry Garfield wrote: > The more I think on this, the more I think that the auto-unsetting behavi= or of a `let` would be useful *only* in combination with some other existin= g block, not as its own block. > > if (let $x=3Dstuff(); $x < 1) { ... } > > for (let $i =3D 0; $i < 10; $i++) { ... } > > foreach (let $arr as $k =3D>v) { ... } (applies to both $k and $v) > > And so on. (I'm not sure if it makes sense on a while? Possibly.) Exac= t syntax above is just spitballing. I remain skeptical about adding block scoping to PHP at all, but if we do pursue this, I have concerns about the approach. I have been working on some tools I need and spent quite some time on php scoping at large, and in detail, that's mainly the reason I am jumping in for a change. My primary concern with the suggestions of integrating let into existing control structures (if (let $x=3Dstuff(); ...), for (let $i =3D 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 hidden bugs that could be hard to catch. Without talking about changing let to "semi" reserved word. Not sure what that means tho'. :) The 'using' syntax proposed earlier in this thread, mapping maybe the 'with' behavior may also provide such an unambiguous definition. If we add block scoping, it needs to be extremely explicit and unambiguous. The RFC's current syntax does achieve this. Alternative syntaxes like using (potentially mapping to with behavior) might also provide that clarity, whereas let integrated into control structures may not. 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. 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. 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 :) In short, If we do proceed, explicitness must be non-negotiable :) best, --=20 Pierre @pierrejoye | http://www.libgd.org