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

fix DOCUMENT_ROOT is always defined in $_SERVER as well as some others #11204

Draft
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public static function getGlobalType(string $var_id, int $codebase_analysis_php_
private static function getGlobalTypeInner(string $var_id, bool $files_full_path = false): Union
{
if ($var_id === '$argv') {
// only in CLI, null otherwise
// if "register_argc_argv = Off" null, except in CLI
return new Union([
Type::getNonEmptyListAtomic(Type::getString()),
new TNull(),
Expand All @@ -600,7 +600,7 @@ private static function getGlobalTypeInner(string $var_id, bool $files_full_path
}

if ($var_id === '$argc') {
// only in CLI, null otherwise
// if "register_argc_argv = Off" null, except in CLI
return new Union([
new TIntRange(1, null),
new TNull(),
Expand Down Expand Up @@ -666,6 +666,12 @@ private static function getGlobalTypeInner(string $var_id, bool $files_full_path
if ($var_id === '$_SERVER' || $var_id === '$_ENV') {
$string_helper = new Union([new TString()], ['possibly_undefined' => true]);
$non_empty_string_helper = new Union([new TNonEmptyString()], ['possibly_undefined' => true]);
$non_empty_string_helper_always_defined = $var_id === '$_SERVER' ?
new Union(
[
new TNonEmptyString(),
]
) : $non_empty_string_helper;

$argv_helper = new Union([
Type::getNonEmptyListAtomic(Type::getString()),
Expand All @@ -687,17 +693,20 @@ private static function getGlobalTypeInner(string $var_id, bool $files_full_path

$arr = [
// https://www.php.net/manual/en/reserved.variables.server.php
'PHP_SELF' => $non_empty_string_helper,
'PHP_SELF' => $non_empty_string_helper_always_defined,
'GATEWAY_INTERFACE' => $non_empty_string_helper,
'SERVER_ADDR' => $non_empty_string_helper,
'SERVER_NAME' => $non_empty_string_helper,
'SERVER_SOFTWARE' => $non_empty_string_helper,
'SERVER_PROTOCOL' => $non_empty_string_helper,
'REQUEST_METHOD' => $non_empty_string_helper,
// technically always defined, however inconsistency with filter_input
// https://github.com/php/php-src/issues/17543
'REQUEST_TIME' => $request_time_helper,
'REQUEST_TIME_FLOAT' => $request_time_float_helper,
'QUERY_STRING' => $string_helper,
'DOCUMENT_ROOT' => $non_empty_string_helper,
// empty string in PHP-CLI, will always be set in PHP
'DOCUMENT_ROOT' => $var_id === '$_SERVER' ? new Union([new TString()]) : $string_helper,
'HTTP_ACCEPT' => $non_empty_string_helper,
'HTTP_ACCEPT_CHARSET' => $non_empty_string_helper,
'HTTP_ACCEPT_ENCODING' => $non_empty_string_helper,
Expand All @@ -712,12 +721,14 @@ private static function getGlobalTypeInner(string $var_id, bool $files_full_path
'REMOTE_PORT' => $string_helper,
'REMOTE_USER' => $non_empty_string_helper,
'REDIRECT_REMOTE_USER' => $non_empty_string_helper,
'SCRIPT_FILENAME' => $non_empty_string_helper,
'SCRIPT_FILENAME' => $non_empty_string_helper_always_defined,
'SERVER_ADMIN' => $non_empty_string_helper,
'SERVER_PORT' => $non_empty_string_helper,
'SERVER_SIGNATURE' => $non_empty_string_helper,
// technically always defined too
// however there seem to be some Apache misconfigurations that make this undefined?
'PATH_TRANSLATED' => $non_empty_string_helper,
'SCRIPT_NAME' => $non_empty_string_helper,
'SCRIPT_NAME' => $non_empty_string_helper_always_defined,
'REQUEST_URI' => $non_empty_string_helper,
'PHP_AUTH_DIGEST' => $non_empty_string_helper,
'PHP_AUTH_USER' => $non_empty_string_helper,
Expand Down
Loading