Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125447 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 qa.php.net (Postfix) with ESMTPS id 32FDD1A00BD for ; Fri, 6 Sep 2024 02:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1725588229; bh=2ymWshUzeztwQPv8p6zlnLg44KyRvWrdm6qVODjzz5U=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=duCb+g0vJe9LsvO+0EgdYWM7CopkxzMiJlOvcq++a30FW/yovOKmWiOR2/QNQrqEO hfmKmvOz0H6TAm6bsyzQA9utVtwC6YGkXbdljgEtlWUMra90bSSrG593cNbipTl4pt +rWuP5jK+7Y0eUkMHw/OUlbWgDSo5vMwpa+429mMpjZofCpz2VVHHLZFKX4s0d8Vpa I2X8Fm3U5LF4OA2u85rEHVSllmLzBLr27FycMMWxKh2EfiPD3HQZLpwQKkOw+Z25M0 mH6nM4tiQHcArkbWNGfr8s3lm9TIndsXMSrFPw1Nyt/TEeFwyYZOg8IdDlLma45A+J Uv3Nq4IWQtkcA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BDAE5180071 for ; Fri, 6 Sep 2024 02:03:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) (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 ; Fri, 6 Sep 2024 02:03:48 +0000 (UTC) Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e1a8ae00f5eso1707549276.0 for ; Thu, 05 Sep 2024 19:01:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1725588109; x=1726192909; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rO1otA84rFXcI1sOGu2oiMVWS3xtpoxFUWHY6XCr6Ks=; b=V5d10WtnPw5g3pI/n9gPOuZfgSK9divz2pzE3OGh3Ub3Y6jv/YSd4UbIVHlfncFpD9 rPypWoYuWBT5QyvqYpEEZ6l8EhZPt+i2SYvUtMLDmkErAX3q23NtIkhim9QsfFsOdbn8 OE+EXQFTe5N+Y8KO8CI5DGZVAEmZiGFDVQR+uB/nGFMxlm2fJV9wgAzaDn/0rfFHswH4 21qjIXDPwajoBRiTdrlWBFYNk5wsoaPlHglFKgwAPq+0uwj/tSPt8oQMqdwDhF/Ha26i tHf6caD8bjzxYKLy0tv3X28+Aj5NhUjWnIAPDdCL3faHCH4q/GvRBHS1Pl2hfxCkqHb/ bVvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725588109; x=1726192909; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rO1otA84rFXcI1sOGu2oiMVWS3xtpoxFUWHY6XCr6Ks=; b=C1lHcGz2TWKRk48mPdUkLQ9oC9eXkvIYSa7veG6uNvO8d5LfuUEUrSPt4Dui6zjb8v Abwr9L5M0IEDU3J/Il7HxTOIqY/orNAl8+zWWuIWTxHLhxXqLU6Ljki/tCeXaWmM0+61 mzx4nB+dTrFfTeu9W+V4TU1gqXikUDWzQ40GoAp6W+GuCGvZz6AJxpp8aKBzGD821lpH 1dWfAHiwTrM9+gyBrnovXx52yuiuNbWA0VlYTvzrFiZpsdYwsGcvC51eZ+BJHx/4nqpT Eq1Eoep1vSwGYZuZPW4+Jl/1If6MrNHAvb12JQZKq/rMu33+rTgGzDEI3Xtnz07/iqW0 1GIQ== X-Gm-Message-State: AOJu0YzzlgudSZWUH3UVGLk3dc8Tegil6pqgfoRjpp1RM/SaDoX5n6vf N0JKYtHzoOOnyXjz1y8lLikZXGGe0HaVs5SYsG1Qm24hyOlWAa9MDdMXFpYLVfVgr4oOswlM2OC aFg0= X-Google-Smtp-Source: AGHT+IG1MHAd9RcPYzl14bl94RWgcC28iIJuxXFVFeAep5XUINbZb1MzS6mZZVuAsowT9cRKG4Mo3Q== X-Received: by 2002:a05:6902:1242:b0:e1a:b04d:673 with SMTP id 3f1490d57ef6-e1d34a3a94emr1382620276.55.1725588108621; Thu, 05 Sep 2024 19:01:48 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e1cfa513825sm1460524276.47.2024.09.05.19.01.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Sep 2024 19:01:47 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.10\)) Subject: Re: [PHP-DEV] Local constants In-Reply-To: Date: Thu, 5 Sep 2024 22:01:46 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <9045A1B9-2880-4FB4-88F4-1AF7EBF0F3E0@newclarity.net> References: <27c3909f-05f4-4256-a447-10e8d8760fff@app.fastmail.com> <420bb5cb-5fca-4f2e-8c68-0ca327cd3392@app.fastmail.com> <7A98532B-7465-4FC5-B7A9-993E7D430EE1@zort.net> <94510a5e-ae23-4118-ac55-2e90c911e7da@app.fastmail.com> <77C2D2CC-5E1E-40D9-9FB3-A5C4A6311669@newclarity.net> To: "Rowan Tommins [IMSoP]" X-Mailer: Apple Mail (2.3696.120.41.1.10) From: mike@newclarity.net (Mike Schinkel) On Sep 5, 2024 at 5:46 PM, wrote: > Block-scoping doesn't have to allow shadowing of names,=20 How exactly would that work? Are you suggesting to restrict the use of = variable names to one per function but still allow for block scoping? Or if not, how would an inner block variable $x not shadow an outer = variable $x? Shadowing is not a feature that is added, it is the result = of block scoping, AFAIK. > and it certainly doesn't have to be achieved by that incredibly hard = to spot syntax. In most languages I've seen, it's indicated by either a = keyword such as "let", "var", or "my"; or by indicating the type of the = variable you're declaring. That declaration syntax is not what makes it problematic, it is the = number of lines between the two declarations. I would not be so against = it if most people kept their functions to 25 lines or less, but what = have I have seen to think 200 to 500 line functions are the norm in = legacy code I've had to work on. But then if most people kept their functions small there would be far = less "need" for block scoping. (Actually =E2=80=94 to channel Rob =E2=80=94= block scoping could encourage people to wrote longer functions which = would definitely be a negative outcome.) > For one thing, it would make me much more likely to accept the = repeated requests for closures which capture parent scope by default, = because it would give a clear opt-out to replace the current clear = opt-in of the use() clause. Scoping within a closure differs from in-line blocks having their own = scope. For one, a closure is separated by a parameter stack whereas a = block shares the stack with its function. Closures can be assigned to = variables and objects properties and also passed to functions, blocks = cannot. Closures have their own return values, blocks have no return = statements thus are coupled to the function's scope. And finally and = most importantly, the point of a closure is to delay or delegate = execution whereas blocks execute inline with the function where they are = located. For all these reasons local scope makes sense in closures = whereas IMO scope in blocks does not. > It's something I'd really like to see in PHP.=20 Be careful what you wish for. But don't say I did not warn you if it = comes to pass. > I've never found myself wishing for local constants, but never really = used a language with them, so maybe I'd find them valuable if they were = added. Ignorance is bliss. And I mean that literally, not pejoratively. > For completeness, I'll mention that *typed* local variables are = another related concept, which has also come up in the past. You'll get no argument from me on type local vars. > The big challenge in all of them is that these are big fundamental = language changes, which require an expert knowledge of how the language = works under the hood=20 Really? I believe what the OP was asking for =E2=80=94 or at least it is = what I would be interested in =E2=80=94 are immutable variables that we = could conveniently declare with `const`. I could be wrong but it seems = the only thing it would require is the compiler to throw an error when = asked to generate a variable assignment opcode to any variable declared = as a const. The above assumes piggybacking on variables with `$` syntax vs. no-`$` = syntax, so maybe using `const` would not be the best keyword. We could = use `var` but that doesn't indicate immutability. =20 Or it may possible that implementing as `const` w/o `$` syntax would not = be hard given that global const names are already recognized by the = parser. And they could internally be kept on the same stack as = variables. > Let's not get too deep into discussing the colour of the bikeshed = before we've worked out if there's space to build one. It is ironic you say we should make sure it's possible before we discuss = if we want it. I know I have heard the opposite many times on this list = =E2=80=94 make sure we even want it before we worry about how to = implement =E2=80=94 although I cannot say for sure that it was ever you = that said that. Whatever the case, of the features that have been implemented in recent = years I find it hard to believe adding local constants would be nearly = as hard as some of those features. Certainly easier than aviz. -Mike=