Hi
Am 2025-11-09 16:07, schrieb Larry Garfield:
Bob, you seem to be focused on the "manual call" case. That... is not
a case that exists. I cannot think of any situation where a user
creates a context manager and then calls enter/exit context themselves
that isn't a "stop that, you're doing it wrong" situation.
See my sibling reply to Rowan
(https://news-web.php.net/php.internals/129468).
By the same token, you *can* implement Iterator and then call current()
and next() and valid() yourself... but odds are you're doing something
wrong, and it's very easy to screw things up if you call those methods
in the wrong order or too many times or whatever. If you implement
Iterator, you're supposed to use it with foreach(). Doing anything
else with it is "well technically that maybe works, but please don't."
You are wrong here. Manually interacting with an Iterator is not just
safe, it is also necessary for some use cases. The simplest example
would be iterating two Iterators in lock-step (i.e. doing a `zip()`
operation / array_combine()).
As Rowan noted, calling __construct() or __destruct() yourself is also
possible, and can cause things to go sideways, and if they do then it's
your own damned fault, don't do that.
The same is true here. Someone manually calling enterContext and then
not calling exitContext() is... simply not a use case that matters,
because there's no good reason to ever do so. The only effort the RFC
needs to make in this regard is say "don't do that."
See sibling reply for an explanation how `__construct()` is different.
Best regards
Tim Düsterhus