-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Error: Argument #2 ($array) must be of type array, null given - Validation.php #8134
Comments
Hello. I found the solution by changing the following line in the system\Validation\Validation.php file Line 481: /** @var IncomingRequest $request */
if (strpos($request->getHeaderLine('Content-Type'), 'application/json') !== false) {
// $this->data = $request->getJSON(true);
$this->data = $request->getJSON(true) ?? [];
return $this;
} |
Thank you for reporting. The error should not be thrown, but if |
It is strange. Because there is no change in Validation except the |
@codeigniter4/core-team public function testJsonInputInvalid(): void
{
$config = new App();
$json = 'invalid';
$request = new IncomingRequest($config, new URI(), $json, new UserAgent());
$request->setHeader('Content-Type', 'application/json');
$rules = [
'role' => 'if_exist|max_length[5]',
];
$result = $this->validation
->withRequest($request->withMethod('POST'))
->setRules($rules)
->run();
$this->assertTrue($result);
$this->assertSame([], $this->validation->getErrors());
$this->assertSame([], $this->validation->getValidated());
} |
Hello, I was checking more carefully and I found that if you make a GET request with the header |
It is not necessary to modify the line that I had named, it is just knowing how to put the headings for each case. But they should clarify it in the documentation. |
@xonipatino I sent PR #8135 |
@kenjis does the doc fix make your question above irrelevant? I didn't understand it at first read but I can process to more if it is still relevant. |
@MGatner I must say no? It is just a fix to a incorrect sample code that was pointed out by the reporter of this. The TypeError issue still remains. |
Okay I have now fully read and understood the issue. Yes, this is a bug in Validation - In my opinion this feature of Validation is assuming too much from the underlying stack and it should be pulled. We cannot assume a particular API schema nor even RESTful protocols. If things a desirable feature it should be moved somewhere appropriate, to |
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:
and returns:
Expected Output
a JSON of data or a JSON with invalid input information
Anything else?
This was working in CI 4.4.2
The text was updated successfully, but these errors were encountered: