Skip to content

Commit c658c06

Browse files
committed
refactor: drop request_order param from getRequestData() and use ini_set in tests
Address review feedback: remove the test-only \ parameter and cast ini_get() results to string so they compare against the empty string. Tests now set request_order via ini_set(). Also reorder the changelog entry alphabetically under HTTP.
1 parent 4627d7e commit c658c06

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

‎system/Superglobals.php‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,17 @@ public function setRequestArray(array $array): self
397397
* stale. This method returns the current merged values so callers can
398398
* read up-to-date request data without relying on the stale $_REQUEST.
399399
*
400-
* @param string|null $requestOrder Overrides the ini setting for testing.
401-
*
402400
* @return array<string, request_items>
403401
*/
404-
public function getRequestData(?string $requestOrder = null): array
402+
public function getRequestData(): array
405403
{
406-
$requestOrder ??= ini_get('request_order');
404+
$requestOrder = (string) ini_get('request_order');
407405

408-
if ($requestOrder === false || $requestOrder === '') {
409-
$requestOrder = ini_get('variables_order');
406+
if ($requestOrder === '') {
407+
$requestOrder = (string) ini_get('variables_order');
410408
}
411409

412-
if ($requestOrder === false || $requestOrder === '') {
410+
if ($requestOrder === '') {
413411
$requestOrder = 'GP';
414412
}
415413

‎tests/system/SuperglobalsTest.php‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,13 @@ public function testGetRequestDataReflectsGetChanges(): void
327327

328328
public function testGetRequestDataMergesCookie(): void
329329
{
330+
ini_set('request_order', 'GPC');
331+
330332
$this->superglobals->setGetArray(['get_key' => 'get_value']);
331333
$this->superglobals->setPostArray(['post_key' => 'post_value']);
332334
$this->superglobals->setCookieArray(['cookie_key' => 'cookie_value']);
333335

334-
$data = $this->superglobals->getRequestData('GPC');
336+
$data = $this->superglobals->getRequestData();
335337

336338
$this->assertSame('get_value', $data['get_key']);
337339
$this->assertSame('post_value', $data['post_key']);
@@ -345,35 +347,46 @@ public function testGetRequestDataRespectsOrder(): void
345347
$this->superglobals->setCookieArray(['shared' => 'cookie']);
346348

347349
// Later sources overwrite earlier ones, matching PHP's request_order.
348-
$this->assertSame('post', $this->superglobals->getRequestData('GP')['shared']);
349-
$this->assertSame('cookie', $this->superglobals->getRequestData('GPC')['shared']);
350-
$this->assertSame('get', $this->superglobals->getRequestData('PG')['shared']);
350+
ini_set('request_order', 'GP');
351+
$this->assertSame('post', $this->superglobals->getRequestData()['shared']);
352+
353+
ini_set('request_order', 'GPC');
354+
$this->assertSame('cookie', $this->superglobals->getRequestData()['shared']);
355+
356+
ini_set('request_order', 'PG');
357+
$this->assertSame('get', $this->superglobals->getRequestData()['shared']);
351358
}
352359

353360
public function testGetRequestDataIgnoresUnknownOrderTypes(): void
354361
{
362+
ini_set('request_order', 'GX');
363+
355364
$this->superglobals->setGetArray(['get_key' => 'get_value']);
356365

357-
$data = $this->superglobals->getRequestData('GX');
366+
$data = $this->superglobals->getRequestData();
358367

359368
$this->assertSame(['get_key' => 'get_value'], $data);
360369
}
361370

362371
public function testGetRequestDataPreservesNumericKeys(): void
363372
{
373+
ini_set('request_order', 'G');
374+
364375
$this->superglobals->setGetArray([100 => 'foo']); // @phpstan-ignore argument.type (numeric keys are valid in superglobals, e.g. ?100=foo)
365376

366-
$data = $this->superglobals->getRequestData('G');
377+
$data = $this->superglobals->getRequestData();
367378

368379
$this->assertSame([100 => 'foo'], $data);
369380
}
370381

371382
public function testGetRequestDataMergesRecursively(): void
372383
{
384+
ini_set('request_order', 'GP');
385+
373386
$this->superglobals->setGetArray(['a' => ['x' => 'get']]);
374387
$this->superglobals->setPostArray(['a' => ['y' => 'post']]);
375388

376-
$data = $this->superglobals->getRequestData('GP');
389+
$data = $this->superglobals->getRequestData();
377390

378391
$this->assertSame(['a' => ['x' => 'get', 'y' => 'post']], $data);
379392
}

‎user_guide_src/source/changelogs/v4.7.5.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ Bugs Fixed
5858
- **Files:** Fixed a bug where ``File::move()`` and ``UploadedFile::move()`` set executable and overly permissive file permissions (``0777 & ~umask()`` instead of ``0666 & ~umask()``), and ``UploadedFile::move()`` targeted the parent directory instead of the destination file for ``chmod()``.
5959
- **Helpers:** Fixed a bug where ``get_dir_file_info()`` returned incomplete entries for subdirectories and missing files instead of omitting them.
6060
- **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden).
61+
- **HTTP:** Fixed a bug where ``IncomingRequest::getVar()`` returned stale data after ``$_GET`` was updated during URI parsing. It now returns a merged view of ``$_GET``, ``$_POST``, and ``$_COOKIE`` (respecting the ``request_order`` ini setting) instead of reading the stale ``$_REQUEST``.
6162
- **I18n:** Fixed a bug where ``Time::today()``, ``Time::yesterday()``, and ``Time::tomorrow()`` ignored the specified ``$timezone`` and ``setTestNow()`` when calculating the day.
6263
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
6364
- **Validation:** Fixed a bug where ``valid_cc_number`` accepted non-digit characters (e.g., a decimal point) in the card number. Such values could pass the Luhn check and triggered an ``Undefined array key`` warning inside it; the number is now checked with ``ctype_digit()``.
64-
- **IncomingRequest:** Fixed a bug where ``getVar()`` returned stale data after ``$_GET`` was updated during URI parsing. It now returns a merged view of ``$_GET``, ``$_POST``, and ``$_COOKIE`` (respecting the ``request_order`` ini setting) instead of reading the stale ``$_REQUEST``.
6565

6666
See the repo's
6767
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)