Skip to content

Commit

Permalink
Merge pull request #8666 from weirdan/remove-argc-argv-from-env
Browse files Browse the repository at this point in the history
Remove `argc` and `argv` elements from `$_ENV`
  • Loading branch information
orklah committed Nov 5, 2022
2 parents 1e454fa + 81423dc commit 0e1c638
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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
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 0e1c638

Please sign in to comment.