Hi Larry,

Thanks. I think most of this comes down to a distinction the RFC hasn't 
stated, and I'd like to make it the core of the next version.

PHP has two kinds of globals. $GLOBALS, class statics and static locals 
are the application's: loaded once, shared by all the code. The $_* 
arrays ($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, $_REQUEST and 
$_SESSION) are something else: they describe the one thing being 
handled. Today there is only ever one of those per process, so the two 
kinds look the same. Scope separates them. I propose to call the second 
kind scope globals: each scope has its own set, and a new scope starts 
with them empty, just as a new process starts with empty globals. $_ENV 
is not one of them: it describes the process, and getenv() is the 
reliable way to read it anyway.

That one definition answers most of the open points:

- Not only requests: a scope global belongs to a scope, whatever the 
scope is used for, whether a request, a test or a guarded call. The RFC 
never needs the word "request".
- Legacy code: an empty scope global is not a new state. unset($_SERVER) 
or $_GET = [] produce it today. Whoever creates a scope and wants code 
under it to see a request fills in what that code needs, including the 
locale and the timezone. If they don't, I take it that they mean those 
to be empty. Those can be three different people, but only the one 
creating the scope can know what it should contain, so the 
responsibility is theirs.
- Objects: with $_GET = new User() in the creator, a new scope does not 
get that instance unless someone copies it in, in code they can see.
- Session: $_SESSION is a scope global backed by a store. A new scope 
has no session started, as at the beginning of a request, and 
session_start() inside the scope opens one there.
- Grouping: I agree with you on output and ini; both start fresh. The 
superglobals are the scope globals, and copying them in is four lines of 
userland code, as your example shows. I'd rather keep that explicit than 
add flags.

On using: if it lands and Scope can support it efficiently, I'd support 
that, and it is a nice use case. But using is about the locals of a 
function, and a block inside a function is not a stack frame, so it 
makes the mapping from a scope to its stack frame less clear. I have no 
strong opinion either way and would leave that decision to those who 
define using.

Frode Børli

Reply via email to