Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove argc and argv elements from $_ENV #8666

Merged
merged 1 commit into from Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
'
];
}
}