Hi

Am 2025-11-04 03:08, schrieb Ben Ramsey:
In general, I support this RFC. I’d like to see examples from other programming languages, though. You mention C# and Hack above. Can you elaborate in the RFC on how they implement this functionality? What about other programming languages? I know some (Rust maybe?) are scoped to blocks by default.

Please have a look at Seifeddine's previous reply to Edmond (https://news-web.php.net/php.internals/129076) and my reply to Arnaud that I just sent (https://news-web.php.net/php.internals/129087).

There are two things to consider when comparing against other programming languages. PHP's semantics do not exactly fit any of these, which means that transferring some concept from another programming language directly does not work.

1. Scoping:

Many programming languages with explicit variable declarations are block scoped. This includes Rust (which you correctly mentioned), but also C, C++, Java, JavaScript (with let and const). Some of them allow shadowing variables from the scope and some don't.

2. Handling of Lifetimes:

As I mentioned in my reply to Arnaud, PHP is pretty unique in the list of programming languages with automated memory management in that it does not primarily use an “unpredictable” garbage collector for memory management, but instead uses reference counting with reliable destructor semantics (that are documented). This is different from e.g. Java where the so-called “finalizers” run at an unpredictable point in time when the GC feels like cleaning up an object. PHP's semantics are close to those of C++ (where this kind of memory management is called RAII) or Rust.

For this reason, PHP just needs some generic “syntactic sugar” for `unset()` that is compatible with all existing functionality using `__destruct()` for those RAII semantics.

Best regards
Tim Düsterhus

Reply via email to