8000 [HttpFoundation] Mising array return type in Symfony\Component\HttpFoundation\InputBag::get · Issue #41800 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Mising array return type in Symfony\Component\HttpFoundation\InputBag::get #41800

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

Closed
gdejong opened this issue Jun 23, 2021 · 2 comments

Comments

@gdejong
Copy link
gdejong commented Jun 23, 2021

Symfony version(s) affected: v5.3.2

Description
When submitting a form with square brackets after the variable name, PHP parses it into an array.

The type hint in \Symfony\Component\HttpFoundation\InputBag::get is set to:

@return string|int|float|bool|null

while the method will can also return an array.

How to reproduce

Require symfony/http-foundation in your composer.json

Create an index.html file:

<form method="POST" action="request.php">
    <input type="text" name="settings[first]">
    <input type="text" name="settings[second]">

    <input type="submit">
</form>

Create a request.php file:

<?php

use Symfony\Component\HttpFoundation\Request;

require_once __DIR__. "/vendor/autoload.php";

$r = Request::createFromGlobals();

echo "<pre>";
print_r($r->request->get("settings"));
echo "</pre>";

After filling out the form with values "1" and "2" it will display:

Array
(
    [first] => 1
    [second] => 2
)

Possible Solution
The docblock could be extended to:

@return string|int|float|bool|null|array

Additional context
See https://www.php.net/manual/en/faq.html.php#faq.html.arrays

I found this because Psalm gave me an error:

ERROR: InvalidArrayAccess Cannot access array value on non-array variable $r of type scalar (see https://psalm.dev/005)
@ro0NL
Copy link
Contributor
ro0NL commented Jun 23, 2021

see #41766

@gdejong
Copy link
Author
gdejong commented Jun 23, 2021

Whoops my bad, will close. I must have searched for issues and not pull requests mentioning "InputBag". Thanks!

@gdejong gdejong closed this as completed Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0