Hi

On 11/12/25 10:53, Tim Düsterhus wrote:
I do see the advantage of forcing them to the start, though. Languages
in the Pascal family might be another comparison to explore - variables
are all declared in a separate block at the top of a function.
Off-hand, I'm not sure if any allow an arbitrary nested block just to
introduce additional variables.

We'll look into more research in that direction.

From what I see in Pascal you would need to declare a “nested procedure” that can then access the variables of the outer prodecure, not dissimilar from a Closure with autocapturing.

We have now added a “Design Choices” section to the RFC explaining why we opted for “declarations need to be at the start of the scope”:

https://wiki.php.net/rfc/optin_block_scoping#design_choices

While it does not directly compare with any language (except for JavaScript), it mentions auto-vivification and scope-introspection functionality, which as far as we are aware doesn't exist to this extend in (similar) languages with block scoping and which is an important part of the requirement.

It also points out how it will not require additional nesting in practice. When there's already a block (particularly `if()`), one can put the block statement directly into the construct without additional braces.

Given the previous opinions of “please don't overload `use()` further”, we also renamed the keyword to `let()` which fits the “block scoping” semantics best, particularly when also considering the possible future scope for `foreach()` scoping.

Best regards
Tim Düsterhus

Reply via email to