Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Bug: `getVar()` behaves inconsistently with GET parameters

Aberta
#9,872 6 comentários 2 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@rahul05ranjan já está trabalhando nisso.

Desde 9/10/2026.

  • #10205 de @jalexiscv — fechado sem integrar
  • #10587 de @rahul05ranjan — fechado sem integrar
  • #10606 de @rahul05ranjan — aberto

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
php
Domínio
api, backend

Direção de pesquisa

Comece com o teste referenciado em tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php e com as atualizações das superglobais em system/HTTP/SiteURIFactory.php. Leia system/Validation/Validation.php e system/HTTP/IncomingRequest.php para rastrear como withRequest() usa getVar(). Considera-se concluído quando a asserção de $_REQUEST do teste passa e validator->withRequest() funciona corretamente sem violar a semântica pretendida das requisições do PHP.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug
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:

https://github.com/codeigniter4/CodeIgniter4/blob/11f0130a5ecc447d5a4c21b2ba991ea381433949/tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php#L226-L241

As you may notice in the above test, SiteURIFactory updates some superglobals, here:

https://github.com/codeigniter4/CodeIgniter4/blob/11f0130a5ecc447d5a4c21b2ba991ea381433949/system/HTTP/SiteURIFactory.php#L162-L175

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.

https://github.com/codeigniter4/CodeIgniter4/blob/11f0130a5ecc447d5a4c21b2ba991ea381433949/system/Validation/Validation.php#L505-L527

https://github.com/codeigniter4/CodeIgniter4/blob/11f0130a5ecc447d5a4c21b2ba991ea381433949/system/HTTP/IncomingRequest.php#L496-L506

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?

https://forum.codeigniter.com/showthread.php?tid=93652

Linguagem predominante
PHP
Estrelas
6k
Forks
2k
Merge médio
1d 22h
PRs com merge (30d)
59

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de codeigniter4/CodeIgniter4

Todas as issues de codeigniter4/CodeIgniter4

Issues semelhantes

Mais issues de PHP

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.