Skip to content

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

Merged
harikt merged 1 commit into
auraphp:2.xfrom
zkwbbr:2.x
Mar 4, 2024
Merged

Make sure only arrays are passed in foreach()#65
harikt merged 1 commit into
auraphp:2.xfrom
zkwbbr:2.x

Conversation

@zkwbbr

@zkwbbr zkwbbr commented Feb 3, 2024

Copy link
Copy Markdown
Contributor

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)
Comment thread src/Request/Files.php
// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

harikt commented Feb 20, 2024

Copy link
Copy Markdown
Member

@zkwbbr are you using this package currently ?

@zkwbbr

zkwbbr commented Feb 23, 2024

Copy link
Copy Markdown
Contributor Author

@zkwbbr are you using this package currently ?

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

@harikt

harikt commented Feb 26, 2024

Copy link
Copy Markdown
Member

@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

zkwbbr commented Feb 26, 2024

Copy link
Copy Markdown
Contributor Author

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

harikt commented Mar 4, 2024

Copy link
Copy Markdown
Member

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

Thank you. And sorry for the delay.

@zkwbbr

zkwbbr commented Mar 4, 2024

Copy link
Copy Markdown
Contributor Author

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