Bug: `getVar()` behaves inconsistently with GET parameters
維護者通常 1 天內回覆
@rahul05ranjan 已經在處理了。
開始於 2026年10月9日。
評估
研究方向
從 tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php 中參照的測試,以及 system/HTTP/SiteURIFactory.php 中的超全域變數更新開始。閱讀 system/Validation/Validation.php 和 system/HTTP/IncomingRequest.php,以追蹤 withRequest() 如何使用 getVar()。完成的標準是測試中的 $_REQUEST 斷言通過,且 validator->withRequest() 能夠正確運作,同時不違反預期的 PHP 請求語意。
由索引模型根據 Issue 內容生成。
描述
PHP Version
8.4
CodeIgniter4 Version
4.6.4
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter)
Which operating systems have you tested for this bug?
macOS
Which server did you use?
cli-server (PHP built-in webserver)
Environment
development
Database
What happened?
In some cases, using $validator->withRequest() will not work correctly. Let's consider this test:
As you may notice in the above test, SiteURIFactory updates some superglobals, here:
The problem is that while $_SERVER['QUERY_STRING'] and $_GET are being updated, the $_REQUEST isn't. And $_REQUEST is needed to make getVar() work correctly.
Steps to Reproduce
public function testQueryStringWithQueryStringAndRequest(): void
{
// /index.php?/ci/woot?code=good#pos
$_SERVER['REQUEST_URI'] = '/index.php?/ci/woot?code=good';
$_SERVER['QUERY_STRING'] = '/ci/woot?code=good';
$_SERVER['SCRIPT_NAME'] = '/index.php';
// these are always the same at the beginning
$_GET['/ci/woot?code'] = 'good';
$_REQUEST['/ci/woot?code'] = 'good';
$factory = $this->createSiteURIFactory($_SERVER);
$expected = 'ci/woot';
$this->assertSame($expected, $factory->detectRoutePath('QUERY_STRING'));
$this->assertSame('code=good', $_SERVER['QUERY_STRING']);
$this->assertSame(['code' => 'good'], $_GET);
// this will fail
$this->assertSame(['code' => 'good'], $_REQUEST);
}
Expected Output
Validation method $validator->withRequest() should work correctly.
The most tempting solution is to add syncRequestAfterGetChange() to Superglobals and call it from SiteURIFactory whenever $_GET is modified. This would keep $_REQUEST synchronized with current values.
The downside is it introduces "magic" behavior that violates standard PHP semantics where $_REQUEST is populated once and never auto-updated. However, since we update $_GET as a "standard", behavior, then updating $_REQUEST may be acceptable?
I was thinking about something like this:
public function syncRequestAfterGetChange(): void
{
$requestOrder = ini_get('request_order') ?: ini_get('variables_order');
$this->request = [];
foreach (str_split($requestOrder) as $type) {
match ($type) {
'G' => $this->request = array_merge($this->request, $this->get),
'P' => $this->request = array_merge($this->request, $this->post),
'C' => $this->request = array_merge($this->request, $this->cookie),
default => null,
};
}
$_REQUEST = $this->request;
}
But I'm unsure if this is the right direction.
Anything else?
- 主要語言
- PHP
- 星號
- 6k
- 分支
- 2k
- 平均合併
- 1 天 22 小時
- 30 天內合併 PR
- 59
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
codeigniter4/CodeIgniter4 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
codeigniter4/CodeIgniter4#10616 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 35/100
codeigniter4/CodeIgniter4#10618 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 62/100
codeigniter4/CodeIgniter4#10617 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 25/100
codeigniter4/CodeIgniter4#10615 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 48/100
codeigniter4/CodeIgniter4#10589 · 3 則留言 ·
維護者通常 1 天內回覆
查看 codeigniter4/CodeIgniter4 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 84/100
WordPress/hosting-handbook#506 ·
維護者通常 2 天內回覆
-
Installing a plugin with composer_packages installs dev dependencies and breaks the autoloader (Error 500)可能已有人在做 @Boy132 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
nginx: static-file locations drop the security headers, and the dotfile deny is matched after them未關閉bug Low Security
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 78/100
backdrop-contrib/commerce#60 ·
-
難度 1/5 1 小時以內 新手友好度 76/100