Make sure only arrays are passed in foreach()#65
Conversation
Fix errors like this: foreach() argument must be of type array|object, string given on /vendor/aura/web/src/Request/Files.php (79)
| // not a target, create sub-elements and init them too | ||
| foreach ($src as $key => $val) { | ||
| $tgt[$key] = array(); | ||
| $this->init($val, $tgt[$key]); |
There was a problem hiding this comment.
I think probably the best way is to check is_array before this init method.
There was a problem hiding this comment.
Not sure if I follow you, you mean like this?
$tgt[$key] = array();
if (is_array($tgt[$key])
$this->init($val, $tgt[$key]);
But that will always be an array because of the previous line: $tgt[$key] = array();?
There was a problem hiding this comment.
foreach is on the first argument passed. That means it is $val should be an array .
|
@zkwbbr are you using this package currently ? |
Yes I am. This issue happens when files are uploaded. |
|
@zkwbbr can you tell me how I can reproduce this error with some basic code you are testing. According to the error you mentioned is line 79.
and from the diff of the code it shows only 78 lines. So I would like to do a test before I merge this. |
Sorry, the error line # is actually 72. Here's a simple code where the error occurs upon file upload: Upon submit, you should receive an error like this:
Tested on: PHP 8.1 and 8.2 |
|
Thank you. And sorry for the delay. |
No problem, thank you :) |
Fix errors like this:
foreach() argument must be of type array|object, string given on /vendor/aura/web/src/Request/Files.php (79)