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

Make sure only arrays are passed in foreach() #65

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Request/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Copy link
Member

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.

Copy link
Contributor Author

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();?

Copy link
Member

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 .

if (is_array($src)) {
foreach ($src as $key => $val) {
$tgt[$key] = array();
$this->init($val, $tgt[$key]);
}
}
}
}
Expand Down
Loading