Skip to content

Bug: $this->request->getGetPost() is inconsistent with $this->request->getGet() #10361

Description

@daveherman71

PHP Version

8.4

CodeIgniter4 Version

4.7.2

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli-server (PHP built-in webserver)

Environment

development

Database

MySQL 8.4.9

What happened?

I receive values to a page which I need to parse into an array. I am using $this->request->getPost([ ... ]) to ensure that only the values I require are parsed. This works as expected.

I have an instance where the same page is called with values being passed via the query string so I use $this->request->getGet([ ... ]) to parse the query string.

I don't know whether the request is going to come via GET or POST so naturally I would like to use $this->request->getPostGet([ ... ]) however an error is thrown instead.

Steps to Reproduce

$values = $this->request->getPost([ 'IPAddress' ]);
print_r($values);

// Array ( [IPAddress] => NULL )

$values = $this->request->getGet([ 'IPAddress' ]);
print_r($values);

// Array ( [IPAddress] => NULL )

$values = $this->request->getPostGet([ 'IPAddress' ]);
print_r($values);

// Expected -- Array ( [IPAddress] => NULL )

Expected Output

When I run $values = $this->request->getPostGet([ 'IPAddress' ]); I expected to get an array as I do with getGet() or getPost(), however an error is thrown instead:

TypeError
CodeIgniter\Superglobals::post(): Argument #1 ($key) must be of type string, array given, called in [Folder]\vendor\codeigniter4\framework\system\HTTP\IncomingRequest.php on line 604

The same happens if I call $this->request->getGetPost([ ... ])

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions