-
Notifications
You must be signed in to change notification settings - Fork 22
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
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)
@@ -69,9 +69,11 @@ protected function init($src, &$tgt) | |||
} | |||
} else { | |||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think probably the best way is to check is_array before this init method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Released : https://github.com/auraphp/Aura.Web/releases/tag/2.2.1 . 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)