Re: [RFC] Scope
| From: | Larry Garfield | Date: | Wed, 11 Nov 2026 20:18:37 +0000 |
| Subject: | Re: [RFC] Scope | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-133081@lists.php.net to get a copy of this message | ||
On Wed, Nov 11, 2026, at 10:48 AM, Frode Børli wrote:
> Hi Larry, Côme, Rowan, Kévin,
>
> A question of direction, since all of you have touched it from different
> sides.
>
> The RFC today is deliberately the small end of something we know the
> full size of: Swerve (0.2, in release candidates) runs concurrent
> requests on top of the CLI SAPI with all of it isolated per request,
> through ext-scope and the phasync extension. Beyond the superglobals,
> the session, the locale and the timezone that the RFC covers, that means
> the whole of the request info (method, URI, query string, content type
> and length, cookies, auth), the request body and uploaded files,
> filter's raw input, REQUEST_TIME, and on the output side the
> output-buffer stack, zlib's compression state, the header list with
> headers_sent and the header callback, connection_status, and the
> shutdown functions. The output half is not just state to swap: it needs
> a per-request sink, which means a request/response contract that the
> server implements, with write, read, send headers and flush. Error
> handlers, ini_set() values, the last-error functions, setlocale(),
> chdir(), statics and $GLOBALS stay shared in that design too.
>
> Two ways to get there from here:
>
> 1. Minimal, then opt in over time. Scope is an identity, and isolation
> is requested per concern with a bitmask, new Scope(isolate:
> Scope::REQUEST | Scope::TIMEZONE); an isolated concern starts fresh, an
> unisolated one is shared with the creator, and the engine gives core and
> extensions enter/leave hooks per bit so each owns its part. Later RFCs
> add bits; code that never asked for a bit is never affected by it, which
> I think answers both Larry's landmine and Côme's question. Scope::ALL
> means everything this version can isolate and grows like E_ALL. This RFC
> would define the mechanism and the first bits.
>
> 2. All in. The same mechanism, plus the request and response contract
> and the input/output bits, in one RFC. It is the complete picture, and
> it is the concurrent counterpart of Kévin's request lifecycle hooks, so
> the two could be designed together. It is also a much larger jump, and a
> much larger discussion.
>
> I am not against the second; I started small because the first step is
> the one that has to be in the engine, and the rest can follow once it is
> in. But if you would rather see the whole shape before voting on any of
> it, I'd rather hear that now than after the vote opens.
>
> Best regards,
> Frode Børli
Proper sizing of an RFC is a hotly debated topic, and if you ask 5 core devs you'll get 12
different answers. :-)
My own stance is that you should at the very least design the "full picture," even if you
break it up into pieces to implement. For example, the aviz and property hooks RFCs were designed
and written together, and some syntax choices in one were essentially dictated by the knowledge that
we were planning to have the other. That meant that the two features "clicked together"
much more naturally, even though we split it into two RFCs that could both justify themselves.
(Whereas properties on interfaces didn't really make any sense on their own, unless accompanied
by aviz and/or hooks, so we didn't split that off.)
In this case, for example, by my count you list 21 pieces of ambient state that need to be addressed
for the full picture. So if they're all opt-in, that means we have 21 different bit flags (22
if you count ALL) to opt into. That seems... problematic, just from a DX perspective. Some of them
may be coupled together as a single flag, but it's still a big list. So, knowing that the list
is large, designing it as a piecemeal opt-in seems like a poor design, particularly since,
eventually, the intent is that most code will want to use everything, meaning most scope calls will
need to throw in the ALL flag, even if by then that should be the default.
So I think a key question to ask is, IF we add more ambient state over time, what is the impact on
existing code? (This relates back to my previous email.) Suppose, for example, we have a class
written against a minimal implementation that is just the core scope object and the HTTP
superglobals, which in turn calls legacy code from before scopes exist that uses the HTTP
superglobals. Now we add the default timezone to the ambient state that a scope isolates.
What's the fallout? My thinking is that if the ambient state always clones, then the fallout
is near-zero. If that class has a
new DateTime() in it, and the scope class it happens
to be running in never mentions the default timezone, then it will get a copy of the default
timezone and nothing changes.
If it tries to reset the default timezone, then the behavior changes as the new value only persists
as long as the scope. But that's literally the point, so that seems OK to me.
So it feels to me (as I am thinking aloud) that "always clone ambient state" would allow
us to transparently add more things to the list of affected ambient state in future RFCs without
disruption, which would lead to nice small RFCs that people like. However, I may be wrong in my
assumption that it would "just work", particularly as relates to the output state. So
thinking through and planning out what the output state impact would be if added separately in a
follow up is a worthwhile exercise, which will both give you the design of that feature in the
future and help inform if it even can be in the future or not.
Another possibility is to design and vote at once but implement in chunks. Eg, there's no RFC
for every resource that gets converted to a normal object, because the decision was accepted years
ago that we would do it as possible, so it's been done as-possible. It may be viable to
include in the initial RFC a complete list of everything that will, eventually, get scope-bound, but
explicitly say that it will dribble in over time via many PRs. That may be a good way to simplify
the process rather than having 21 separate RFCs, which just from a process POV will take years and I
don't think benefits anyone. (Core maintainers like Ilija and Arnaud are free to tell me to
shut up on this point if they disagree with this approach.)
--Larry Garfield