Hello, Le jeudi 5 novembre 2026, 18:33:14 heure normale d’Europe centrale Larry Garfield a écrit : > Hi folks. Based on the feedback and problems with the previous Context > Managers RFC, Arnaud and I have a new approach to present: > > https://wiki.php.net/rfc/context-managers-v2 > > It basically swaps the two-method approach in favor of "it's a generator, > you're welcome." The result is, I think, both simpler and more flexible, and > resolves a number of other issues as well. More details in the RFC. > > There is a linked implementation, though Arnaud warns it's only partially > complete so go easy on it. :-) But the design in the RFC is all ready for > review.
I do not understand this sentence: «Additionally, it is legal for a Context
Manager object to return $this as the context variable if that is appropriate
in the specific use case.»
If ContextManager::getContextManager returns $this, which Generator is used 🤔
The whole section «Mixing with try-catch» is also a mystery to me. I do not
understand why "using" would need a short syntax for try catch any more than
any other keyword we often put in a try/catch, nor what the explanations in
there mean.
Is the semi-colon necessary after the closing '}' ? That reads weird, it’s not
clear to me why it’s not a single '}' like after an if or foreach or whatever.
Also, this semi-colon is missing in at least one example.
In the transaction example, $conn does not exist, I suppose both instances
should be $this?
«A return statement inside the BODY will return from the function the code is
currently executing in. A finally block in the generator context manager will
still be executed, but otherwise control returns to the function's caller.»
This is also hard to get for me.
Can you detail what this would output:
function context(): \Generator {
echo "A\n";
yield "B";
echo "C\n";
return "D";
}
var_dump(
using (context() => $c) {
echo "E\n";
return "F";
}
);
Côme
signature.asc
Description: This is a digitally signed message part.
