On Fri, Nov 6, 2026, at 8:51 AM, Sjoerd Langkemper wrote: > On Thu, Nov 5, 2026, at 18:33, Larry Garfield wrote: >> Context Managers RFC, Arnaud and I have a new approach to present: >> >> https://wiki.php.net/rfc/context-managers-v2 > > Thanks. It looks promising. > >> When the using expression ends, VAR is explicitly unset(). > > What happens when VAR was already defined before the context? Is it > masked and restored, or overwritten and unset?
At the moment, in v2 it's overwritten and unset. We can bring back the mask/restore logic if there's interest, but we're not entirely convinced it's needed so left it out of this version for now. (Basically, if you're reusing a variable like that, you know that it's not going to be what it was before. If you do so accidentally, then your function is too long for you to keep in your head and you need to refactor anyway.) >> what the return value of a combined using block should be > > I would say the return value of the outer-most / left-most context > manager. That is equivalent to the nested form. That's my thinking as well, but we wanted to get input from the Crowd(tm). > The compact comma separated syntax could also be added later, so if > this is a difficult point it is also possible to remove this from the > RFC and add it later on. True, though it doesn't seem controversial so I'd rather include it if we can. >> public function transaction(): self > > Should the return type be Generator here? Yep, it should. Fixed now, thanks. --Larry Garfield
