Skip to content

Error: Argument #2 ($array) must be of type array, null given - Validation.php #8134

Description

@xonipatino

PHP Version

8.2

CodeIgniter4 Version

4.4.3

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli-server (PHP built-in webserver)

Database

No response

What happened?

CodeIgniter\\Validation\\DotArrayFilter::run(): Argument #2 ($array) must be of type array, null given, called in ...\\vendor\\codeigniter4\\framework\\system\\Validation\\Validation.php on line 203

Steps to Reproduce

I have the next code:

if (
            !$this->validate(
                [
                    'start' => [
                        'label' => 'Inicio',
                        'rules' => 'if_exist|numeric|integer|is_natural',
                    ],
                    'length' => [
                        'label' => 'Limite',
                        'rules' => 'if_exist|numeric|integer|is_natural_no_zero',
                    ],
                    'columns' => [
                        'label' => 'Columnas',
                        'rules' => 'if_exist|valid_json',
                    ],
                    'order' => [
                        'label' => 'Orden',
                        'rules' => 'if_exist|required_with[columns]|valid_json',
                    ],
                    'filters' => [
                        'label' => 'Filtros',
                        'rules' => 'if_exist|valid_json',
                    ],
                ]
            )
        ) {
            $errores = validation_errors();

            return response()->setJSON(
                [
                    'estado' => false,
                    'msje'   => view_cell(
                        'AlertCell',
                        [
                            'tipo'      => 'warning',
                            'contenido' => ul($errores, ['class' => 'mb-0']),
                        ]
                    ),
                    'errores' => $errores,
                    // Propiedad del datatable para respuesta de error
                    'error'   => current($errores),
                ]
            );
        }

and returns:

{
    "title": "TypeError",
    "type": "TypeError",
    "code": 500,
    "message": "CodeIgniter\\Validation\\DotArrayFilter::run(): Argument #2 ($array) must be of type array, null given, called in C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\vendor\\codeigniter4\\framework\\system\\Validation\\Validation.php on line 203",
    "file": "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\vendor\\codeigniter4\\framework\\system\\Validation\\DotArrayFilter.php",
    "line": 29,
    "trace": [
        {
            "file": "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\vendor\\codeigniter4\\framework\\system\\Validation\\Validation.php",
            "line": 203,
            "function": "run",
            "class": "CodeIgniter\\Validation\\DotArrayFilter",
            "type": "::"
        },
        {
            "file": "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\vendor\\codeigniter4\\framework\\system\\Controller.php",
            "line": 152,
            "function": "run",
            "class": "CodeIgniter\\Validation\\Validation",
            "type": "->"
        },
        {
            "file": "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\app\\Controllers\\InformacionController.php",
            "line": 33,
            "function": "validate",
            "class": "CodeIgniter\\Controller",
            "type": "->"
        },
        {
            "file": "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 942,
            "function": "list",
            "class": "App\\Controllers\\InformacionController",
            "type": "->"
        },
        {
            "file": "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 502,
            "function": "runController",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->"
        },
        {
            "file": "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 361,
            "function": "handleRequest",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->"
        },
        {
            "file": "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\public\\index.php",
            "line": 79,
            "function": "run",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->"
        },
        {
            "file": "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\vendor\\codeigniter4\\framework\\system\\Commands\\Server\\rewrite.php",
            "line": 47,
            "args": [
                "C:\\Users\\xonip\\OneDrive - ADN ERP S.A.S\\www\\local_html\\macc\\public\\index.php"
            ],
            "function": "require_once"
        }
    ]
}

Expected Output

a JSON of data or a JSON with invalid input information

Anything else?

This was working in CI 4.4.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions