Re: [RFC][Discussion] use construct (Block Scoping)
| From: | Rowan Tommins [IMSoP] | Date: | Wed, 05 Nov 2025 20:17:42 +0000 |
| Subject: | Re: [RFC][Discussion] use construct (Block Scoping) | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129092@lists.php.net to get a copy of this message | ||
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]