Repository navigation
fix: set the superglobals like PHP so $_ENV and $_REQUEST reach the script - #17
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
============================================
+ Coverage 93.61% 93.65% +0.03%
- Complexity 578 581 +3
============================================
Files 16 17 +1
Lines 1347 1355 +8
============================================
+ Hits 1261 1269 +8
Misses 86 86 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
nlemoine
force-pushed
the
fix/env-superglobal
branch
from
November 26, 2026 12:18
cfb1ba4 to
7bc0c63
Compare
The bootstrap set the superglobals through $GLOBALS. With auto_globals_jit, on by default, PHP builds $_ENV, $_SERVER and $_REQUEST when it compiles a file that names them, or when filter_input() needs them, and replaced the values set that way. The script got an empty $_ENV and $_REQUEST under the variables_order of the php.ini files PHP ships (GPCS), and the process environment instead of the client's values when no php.ini is loaded (EGPCS). $_SERVER only survived because the CLI SAPI builds it at startup. The bootstrap now assigns every superglobal by name, like Symfony's Request::overrideGlobals(), so they are built while it compiles. $_ENV is now exactly what the client sends, whatever the ini, as the README and SECURITY.md already describe. Behaviour change: with variables_order=EGPCS and no globals handler, the script's $_ENV no longer holds the process environment. Use InheritEnvGlobalsHandler, or getenv(). Extra keys a globals handler adds to the array no longer become global variables in the script.
$_REQUEST was computed in the calling process, with its request_order, and with array_merge(), which drops nested keys and renumbers numeric ones. The script's PHP process now builds it from the $_GET, $_POST and $_COOKIE it receives, with its own request_order (or variables_order), each letter once and a recursive merge, like PHP and Symfony's Request::overrideGlobals(). Globals handlers still see a _REQUEST built the same way. Changes they make to _GET, _POST or _COOKIE now reach $_REQUEST, and a _REQUEST they change themselves is sent as is. The $_REQUEST assertions that were commented out in ClientTest pass again.
PHP falls back to variables_order for $_REQUEST only when request_order is not set. Set but empty, it builds an empty $_REQUEST. ini_get() returns '' in both cases, so the order now comes from ini_get_all(), which gives null for a directive that is not set. Review follow-ups in the same area: - A handler that removes _REQUEST no longer triggers an undefined key warning in the calling process. - The bootstrap no longer fails with a TypeError when a handler sets _GET, _POST or _COOKIE to something other than an array. - The README and the GlobalsHandler docblock say that keys outside the documented shape are ignored, how a changed _REQUEST is handled, and what filter_input() really returns. - Tests pin request_order through a PHP wrapper instead of depending on the php.ini of the machine, and check literal values.
nlemoine
force-pushed
the
fix/env-superglobal
branch
from
November 26, 2026 12:55
9c25358 to
45889df
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
$_ENVand$_REQUESTdid not reach the target script. A GET to?a=1gave$_GET = ['a' => '1']but$_REQUEST = [], and a value aGlobalsHandlerput in$_ENVwas lost.The bootstrap set the superglobals with
$GLOBALS[$name] = .... Withauto_globals_jit=1(the default), PHP builds$_ENV,$_SERVERand$_REQUESTwhen it compiles a file that names them, or whenfilter_input()needs them, and that replaced the values.$_SERVERsurvived only because the CLI SAPI builds it at startup. What the script saw depended on the ini: undervariables_order=GPCS(the value of the php.ini files PHP ships)$_ENVand$_REQUESTwere empty, underEGPCS(PHP's built-in value when no php.ini is loaded, like the official Docker images)$_ENVwas the process environment instead of what the client sent, and$_REQUESTwas still empty.Two commits.
The first one assigns every superglobal by name, like Symfony's
Request::overrideGlobals(), so they are built while the bootstrap compiles.$_ENVis now exactly what the client sends, whatever the ini. That is what the README ("a clean set of superglobals built from the HTTP request only") andSECURITY.mdalready describe, and it is coherent with$_SERVER, which never had the environment withoutInheritEnvGlobalsHandler. This is a behavior change forEGPCSsetups: without a handler, the script's$_ENVno longer holds the process environment.getenv()still works, andInheritEnvGlobalsHandlerbrings the variables back. Also, extra keys a handler adds to the array no longer become global variables in the script, that came from the$GLOBALSloop.The second one builds
$_REQUESTin the script's PHP process, from the$_GET,$_POSTand$_COOKIEit receives and with its ownrequest_order, like PHP andoverrideGlobals()do. Before, it was built in the calling process with its ini, and witharray_merge(), which loses nested keys and renumbers numeric ones. Handlers still see a_REQUEST, changes they make to_GET/_POST/_COOKIEnow reach it, and a_REQUESTthey change themselves is sent as is.I asked for a second opinion on
$_ENVbefore choosing. Merging the client values into what PHP built would have avoided theEGPCSchange, but it makes$_ENVdepend on the ini and lets the parent's$_ENVreach the script without a handler (Symfony Process exports it as real environment variables), which the isolation test is meant to prevent.Tests run the script under
GPCS,EGPCSandEGPCSwithout JIT through a small PHP wrapper passed asphpExecutable, and under severalrequest_ordervalues. The$_REQUESTassertions commented out inClientTest("needs further investigation") pass again. The README now also says thatfilter_input()can't see the emulated superglobals.