Hi Larry, Côme, Two days ago I changed the RFC so that a new scope starts as a copy of its creator's state. Writing that rule out in full, for the extension and for the text, has changed my mind back, and I want to state my position plainly before the text moves again.
The copy rule looks like one rule but is not. The six arrays copy with a reference count, but an object is a handle, not a value: $_SESSION['user'] holding an entity, or $_GET replaced by an ArrayAccess object, which PHP allows, is the same instance in both scopes, and a write inside the new scope reaches the creator. That is the leak a scope exists to prevent. The session has no copy at all: it is a store with a lock, and specifying a copy of it meant choosing between writing under a lock the copy does not hold, a snapshot whose writes vanish, or sharing. Headers and output cannot be copied either. So "a new scope starts as a copy" needs a table of what is copied, what is shared and what is neither, and every later RFC adds a row to it. That is the mess, and the one who pays for it is whoever creates a scope and has to look up, or find out by trial, what came along and what did not. The clean rule is the one the RFC had until 0.9.5: a new scope is a clean slate for the state that follows the scope. It has the state the engine has immediately before the request line is parsed: no query string, no $_POST, no $_SERVER, no session, locale and timezone at their php.ini defaults, and the same for whatever a later RFC moves into the scope. What does not follow the scope is unchanged: $GLOBALS, class statics and static locals are the application's, loaded once and shared by every scope, as globals are in every language with such a construct. It is not a sub scope that inherits some things from the scope that created it. It is a new scope, as if there had been no request before, and whoever creates it puts in it what they want, explicitly. That is one sentence for the request state, it defines "fresh" for every kind of it at once, now and later, and it leaves the programmer in control of what is included and how. On the landmine: I would rather have the one who creates a scope discover loudly that $_GET and $_POST are gone than have some things present and others not. A scope is not something code falls into; the only one who can run your function in a scope is your caller, who can clear $_GET before calling you today. Creating a scope is a deliberate act with a documented meaning, and a loud failure on the first run is a better outcome than a shared object quietly written to from two scopes. That is the version I am comfortable implementing, and it is what the released extension does; the next version of the RFC returns to it unless this discussion shows me wrong. If someone wants a more intertwined Scope, where a new scope inherits part of its creator's state, I would like to hear how, what exactly is inherited and why, including what happens to objects and to the session, because I could not make it hold together. Alternatively, if the list prefers that direction, I am willing to withdraw the RFC and let someone else take it over. Either way I will keep implementing the minimal, clean version in fiber-interop and Swerve. Best regards, Frode Børli
