Skip to content

[HttpFoundation] Type mismatch between Request::$requestFactory and Request::setFactory() #54321

@longwave

Description

@longwave

Symfony version(s) affected

7.0.0

Description

Request declares $requestFactory as a closure:

    protected static ?\Closure $requestFactory = null;

::setFactory() declares its argument as a callable:

    public static function setFactory(?callable $callable): void
    {
        self::$requestFactory = $callable;
    }

How to reproduce

Drupal calls ::setFactory() with a callable that isn't a closure:

$request_factory = new TrustedHostsRequestFactory('localhost');
Request::setFactory([$request_factory, 'createRequest']);

In Symfony 7 this results in

PHP Fatal error:  Uncaught TypeError: Cannot assign array to property Symfony\Component\HttpFoundation\Request::$requestFactory of type ?Closure

Possible Solution

Either convert the callable to a closure internally with Closure::fromCallable() or change the typehint of the setFactory() argument to \Closure, unsure which is the preferred solution here.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions