Uh oh!
There was an error while loading. Please reload this page.
fix: env() TypeError for non-string $_SERVER values + esc() fixes - #10305
Conversation
- env(): guard non-string values (int argc, array argv in CLI) before strtolower() to prevent TypeError under declare(strict_types=1) - esc(): propagate $encoding in recursive array calls (was ignored before), add early return after array processing, replace single static $escaper with static $escapers[] cache keyed by encoding - tests: data-provider test for env() non-string types, three tests for esc() foreach reference leak
53a365d to
449dbaeCompare
michalsn
left a comment
There was a problem hiding this comment.
Please send one change per PR.
This needs a changelog entry.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
michalsn
commented
Jun 12, 2026
Apart from the changelog entry, we also need some tests to prove the fixed |
michalsn
left a comment
There was a problem hiding this comment.
We still need two things - see my previous comment.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
env() TypeError for non-string $_SERVER values + esc() fixesUh oh!
There was an error while loading. Please reload this page.
paulbalandan
commented
Jun 15, 2026
Thank you, @gr8man |
…es (codeigniter4#10305) * fix: env() TypeError for non-string $_SERVER values + esc() fixes - env(): guard non-string values (int argc, array argv in CLI) before strtolower() to prevent TypeError under declare(strict_types=1) - esc(): propagate $encoding in recursive array calls (was ignored before), add early return after array processing, replace single static $escaper with static $escapers[] cache keyed by encoding - tests: data-provider test for env() non-string types, three tests for esc() foreach reference leak * Apply suggestion from @michalsn Co-authored-by: Michal Sniatala <michal@sniatala.pl> * Apply suggestion from @michalsn Co-authored-by: Michal Sniatala <michal@sniatala.pl> * Update system/Common.php Co-authored-by: Michal Sniatala <michal@sniatala.pl> * style: cs-fix * test: add tests for esc() encoding changes and update changelog * Update tests/system/CommonFunctionsTest.php Co-authored-by: Michal Sniatala <michal@sniatala.pl> * docs: move env/esc fix changelog entry to v4.7.4.rst * docs: split Common changelog entry --------- Co-authored-by: Michal Sniatala <michal@sniatala.pl>
Fix:
env()TypeError in CLI +esc()improvementsWhat
Fixes two bugs in
system/Common.php.env()— In CLI,$_SERVERcontains non-string values (argcisint,argvisarray). Passing them tostrtolower()threw aTypeErrorunderdeclare(strict_types=1). Added anis_string()guard before thematchexpression; non-string values are returned as-is.esc()— Three fixes applied together:foreach ($data as &$value)left a dangling reference after the loop; addedunset($value)to prevent silent mutation of the last array element in the calling scope$encodingwas not propagated in recursive array callsstatic $escaperwithstatic $escapers[]keyed by encoding for correct per-encoding cachingTests
Added a data-provider test for
env()covering non-string$_SERVER/$_ENVvalues (int, array, float), and three tests verifying theesc()reference leak is gone.Files changed
system/Common.phptests/system/CommonFunctionsTest.php