Am 22.01.2026, 18:57:04 schrieb Arnaud Le Blanc <[email protected]>:
> On Thu, Jan 22, 2026 at 10:17 AM Tim Düsterhus <[email protected]> wrote: > > > Hi > > > we just opened the vote on the “let construct (Block Scoping)” RFC > > (which was originally proposed as “use construct”, but the keyword > > changed as a result of the discussion). > > > Hi, > > Thank you for your work on this. > > I voted no because the RFC is presented as a way to dispose of > resources immediately (quoting: "This feature provides immense value, > particularly for modern applications built on long-lived servers, > where disciplined and immediate resource cleanup is not just a best > practice, but a necessity for stability and performance."), yet it > doesn't in practice as it relies on reference counting as a proxy for > cleaning up at block exit. > I agree that relying on reference counting can bite you, but I still voted Yes, because - We only have reference counting to rely on in PHP as far as memory goes, and thats what people writing cleanup critical code rely on already. This gives a much nicer syntax. - The future scope lists improvements as next steps, like the error when RC > 1 or Disposable interfaces, this is a first step towards something that is missing dearly. > While reference counting is deterministic, ensuring that a value is > uniquely referenced before leaving a block is impossible, and cannot > be enforced by the block itself. In practice, useful code will send > the resource to other functions or 3rd party code that may retain a > reference to it. Moreover, there are many non-obvious ways in which a > reference count can be increased or a value’s lifetime extended: > exceptions or backtraces may capture arguments, fibers, generators, or > closures with non obvious lifetimes retain their local variables, > closures tend to create cycles, foreach variables are not always > unset, etc. > > Therefore there is a non-zero possibility that a let() statement will > not in fact cleanup the resource, despite the stated goal. Fixing this > later would be a BC break as people may rely on this behavior. > > The RFC refers to similar constructs from other languages, but none of > them rely on reference counting for this purpose. I'm not aware of > languages relying on reference counting for this. > > Best Regards, > Arnaud >
