Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions system/HTTP/SiteURIFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ private function parseRequestURI(): string
parse_str($this->superglobals->server('QUERY_STRING'), $get);
$this->superglobals->setGetArray($get);

// Sync $_REQUEST so that getVar() works correctly
$this->superglobals->syncRequest();

return URI::removeDotSegments($path);
}

Expand Down Expand Up @@ -205,6 +208,9 @@ private function parseQueryString(): string
parse_str($this->superglobals->server('QUERY_STRING'), $get);
$this->superglobals->setGetArray($get);

// Sync $_REQUEST so that getVar() works correctly
$this->superglobals->syncRequest();

return URI::removeDotSegments($path);
}

Expand Down
30 changes: 30 additions & 0 deletions system/Superglobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,34 @@ public function setGlobalArray(string $name, array $array): void
),
};
}

/**
* Rebuilds $_REQUEST from $_GET, $_POST, and $_COOKIE according to PHP's
* request_order / variables_order ini setting.
*
* This is necessary when superglobals like $_GET are modified after the
* initial request population, since PHP does not automatically keep
* $_REQUEST in sync.
*
* @see https://www.php.net/manual/en/ini.core.php#ini.request-order
*/
public function syncRequest(): self
{
$requestOrder = ini_get('request_order') ?: ini_get('variables_order');

$this->request = [];

foreach (str_split($requestOrder) as $type) {
match ($type) {
'G' => $this->request = array_replace($this->request, $this->get),
'P' => $this->request = array_replace($this->request, $this->post),
'C' => $this->request = array_replace($this->request, $this->cookie),
default => null,
};
}

$_REQUEST = $this->request;

return $this;
}
}