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

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

Closed
longwave opened this issue Mar 18, 2024 · 0 comments · Fixed by #54333
Closed

Comments

@longwave
Copy link

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

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