Re: [RFC][Discussion] use construct (Block Scoping)

From: Date: Thu, 06 Nov 2025 02:25:34 +0000
Subject: Re: [RFC][Discussion] use construct (Block Scoping)
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-129104@lists.php.net to get a copy of this message
On Wed, 5 Nov 2025 at 21:18, Rowan Tommins [IMSoP] <imsop.php@rwec.co.uk> wrote: > > On 4 November 2025 19:44:40 GMT, Seifeddine Gmati <azjezz@carthage.software> 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.

« previous php.internals (#129104) next »