Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: public function getJsonVar error in the code #5391

Closed
amigoscs opened this issue Nov 25, 2021 · 1 comment · Fixed by #5392
Closed

Bug: public function getJsonVar error in the code #5391

amigoscs opened this issue Nov 25, 2021 · 1 comment · Fixed by #5392
Assignees
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@amigoscs
Copy link

PHP Version

8.0

CodeIgniter4 Version

4.1.2

CodeIgniter4 Installation Method

Manual (zip or tar.gz)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

No response

What happened?

If "null" is sent to the server and when trying to get data through "Services :: request () -> getVar('myKey')", the error "Argument 2 passed to dot_array_search () must be of the type array..."

Steps to Reproduce

I am sending a POST request without data

Expected Output

Services :: request () -> getVar ('myKey') function should return "null"

Anything else?

File:
system/HTTP/IncomingRequest.php

public function getJsonVar()

Line 540: $data = dot_array_search($index, $this->getJSON(true));

if $this->getJSON(true) returns null then an error appears

Solution:

$getJson = $this->getJSON(true) ?: [];
$data = dot_array_search($index, $getJson);
@amigoscs amigoscs added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 25, 2021
@kenjis
Copy link
Member

kenjis commented Nov 25, 2021

Thank you for reporting. I confirmed the TypeError in develop branch.

<?php
namespace App\Controllers;
class Home extends BaseController
{
    public function index()
    {
        d($this->request->getJsonVar('myKey'));
    }
}
$ php public/index.php 


[TypeError]

dot_array_search(): Argument #2 ($array) must be of type array, null given, called in /Users/kenji/work/codeigniter/CodeIgniter4/system/HTTP/IncomingRequest.php on line 540

at SYSTEMPATH/Helpers/array_helper.php:21

Backtrace:
  1    SYSTEMPATH/HTTP/IncomingRequest.php:540
       dot_array_search('myKey', null)

  2    APPPATH/Controllers/Home.php:9
       CodeIgniter\HTTP\IncomingRequest()->getJsonVar('myKey')

@kenjis kenjis self-assigned this Nov 25, 2021
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Nov 25, 2021
See codeigniter4#5391

[TypeError]
dot_array_search(): Argument #2 ($array) must be of type array, null given, called in .../system/HTTP/IncomingRequest.php on line 540
at SYSTEMPATH/Helpers/array_helper.php:21
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Nov 25, 2021
See codeigniter4#5391

[TypeError]
dot_array_search(): Argument #2 ($array) must be of type array, null given, called in .../system/HTTP/IncomingRequest.php on line 540
at SYSTEMPATH/Helpers/array_helper.php:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants