Skip to content

Commit

Permalink
Remove argc and argv elements from $_ENV
Browse files Browse the repository at this point in the history
Fixes #8662
  • Loading branch information
weirdan committed Nov 5, 2022
1 parent 1e454fa commit 81423dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,9 @@ public static function getGlobalType(string $var_id, int $codebase_analysis_php_
$bool_string_helper = new Union([new TBool(), new TString()]);
$bool_string_helper->possibly_undefined = true;

$detailed_type = new TKeyedArray([
$detailed_type_members = [
// https://www.php.net/manual/en/reserved.variables.server.php
'PHP_SELF' => $non_empty_string_helper,
'argv' => $argv_helper,
'argc' => $argc_helper,
'GATEWAY_INTERFACE' => $non_empty_string_helper,
'SERVER_ADDR' => $non_empty_string_helper,
'SERVER_NAME' => $non_empty_string_helper,
Expand Down Expand Up @@ -727,7 +725,15 @@ public static function getGlobalType(string $var_id, int $codebase_analysis_php_
// phpunit
'APP_DEBUG' => $bool_string_helper,
'APP_ENV' => $string_helper,
]);
];

if ($var_id === '$_SERVER') {
// those elements are not usually present in $_ENV
$detailed_type_members['argc'] = $argc_helper;
$detailed_type_members['argv'] = $argv_helper;
}

$detailed_type = new TKeyedArray($detailed_type_members);

// generic case for all other elements
$detailed_type->previous_key_type = Type::getNonEmptyString();
Expand Down
9 changes: 9 additions & 0 deletions tests/SuperGlobalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@ function returnsList(): array {
',
'assertions' => []
];

yield 'ENV has scalar entries only' => [
'<?php
/** @return array<array-key, scalar> */
function f(): array {
return $_ENV;
}
'
];
}
}

0 comments on commit 81423dc

Please sign in to comment.