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

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

merged 1 commit into from
Mar 4, 2024

Conversation

zkwbbr
Copy link
Contributor

@zkwbbr zkwbbr commented Feb 3, 2024

Fix errors like this:

foreach() argument must be of type array|object, string given on /vendor/aura/web/src/Request/Files.php (79)

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]);
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 .

@harikt
Copy link
Member

harikt commented Feb 20, 2024

@zkwbbr are you using this package currently ?

@zkwbbr
Copy link
Contributor Author

zkwbbr commented Feb 23, 2024

@zkwbbr are you using this package currently ?

Yes I am. This issue happens when files are uploaded.

@harikt
Copy link
Member

harikt commented Feb 26, 2024

@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.

foreach() argument must be of type array|object, string given on /vendor/aura/web/src/Request/Files.php (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.

@zkwbbr
Copy link
Contributor Author

zkwbbr commented Feb 26, 2024

@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.

foreach() argument must be of type array|object, string given on /vendor/aura/web/src/Request/Files.php (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:

<?php

require __DIR__.'/vendor/autoload.php';

$webFactory = new \Aura\Web\WebFactory($GLOBALS);
$request = $webFactory->newRequest();

?>

<form method="post" enctype="multipart/form-data">
	<input type="file" name="file">
	<input type="submit">
</form>

Upon submit, you should receive an error like this:

Warning: foreach() argument must be of type array|object, string given in /../vendor/aura/web/src/Request/Files.php on line 72

Tested on: PHP 8.1 and 8.2

@harikt harikt merged commit ec13a00 into auraphp:2.x Mar 4, 2024
1 of 11 checks passed
@harikt
Copy link
Member

harikt commented Mar 4, 2024

Released : https://github.com/auraphp/Aura.Web/releases/tag/2.2.1 .

Thank you. And sorry for the delay.

@zkwbbr
Copy link
Contributor Author

zkwbbr commented Mar 4, 2024

Released : https://github.com/auraphp/Aura.Web/releases/tag/2.2.1 .

Thank you. And sorry for the delay.

No problem, thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants