On Wed, 5 Nov 2025 at 21:18, Rowan Tommins [IMSoP] <[email protected]> wrote: > > On 4 November 2025 19:44:40 GMT, Seifeddine Gmati <[email protected]> > wrote: > > >This mimics Python's context manager protocol. The `dispose()` method > >would be called before `__destruct`, allowing objects to distinguish > >between successful completion and failure. > > > A clarification here: this would be equivalent to IDisposable in C#, but it > would not be equivalent to the Context Manager protocol in Python. > > The use cases which motivated them are actually quite different: C# needed a > way to handle things like pointers to unmanaged memory, so the design is > closely tied to the actual resource object cleaning up its own internal > state. Python was looking much more generally at common programming patterns, > and a "context manager" can be separate from the resource it is managing, or > even have no associated resource at all, only "enter" and "exit" behaviour. > > > > Rowan Tommins > [IMSoP]
Hi Rowan, My statement that it closely relates to Python, is in the sense that if we were to add a `Disposable` interface, it would need to add additional value beyond what `__destruct` already provides. In C#, `Disposable::Dispose` ( just like in Hack ) receives no information on whether the `using` scope exited successfully or due to an exception, so having this in PHP adds no value that `__destruct` doesn't already provide.
