Skip to content

http-foundation InputBag::get with default value should not return null #91

@raalderink

Description

@raalderink

If you use HTTPFoundation's Request, and then get specific input bags (query/request,...), the get may return string|null. However, if you pass parameter #2 $default as non-null value, it will never return null, and always a string.

So for example this code can never return null;

$request->query->get('name', 'default value');

Currently, because the typehint on the function is string|null, PHPStan will complain if you pass this to a function with a non-null argument, even though it will never return null;

Parameter #2 $name of class Foo constructor expects string, string|null given

This is tested on Symfony 5.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions