Re: [RFC] Context Managers

From: Date: Fri, 28 Nov 2025 08:45:28 +0000
Subject: Re: [RFC] Context Managers
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-129467@lists.php.net to get a copy of this message
Hi

Am 2025-11-06 00:27, schrieb Rowan Tommins [IMSoP]:
I think you may have missed the key distinction between a "Context Manager" (as designed by Python) and a "Disposable" (as used in C# and others): the Context Manager is not the resource itself, it exists only to meet the protocol/interface. In this code: with ( $dbConnection->transaction() as $handle ) {    $handle->execute('I am in the transaction'); } $handle is *not* the value returned by $dbConnection->transaction(), it's the value returned by $dbConnection->transaction()->enterContext().
For reference: This topic was/is also discussed in your sibling thread starting at https://news-web.php.net/php.internals/129464. I also stumbled upon this being completely unexpected from just looking at the code. If multiple participants on this list with a above-average knowledge of PHP (or even engine knowledge) find this unclear, I am really concerned about the clarity for “regular PHP developers”. Best regards Tim Düsterhus

Thread (33 messages)

« previous php.internals (#129467) next »