Skip to content

http-foundation - toArray() will break Laravel projects #38400

@AegirLeet

Description

@AegirLeet

Symfony version(s) affected: 5.2.x (unreleased)

Description
f589ff4 adds a toArray() method with an array return type to the Request class. Laravel currently extends that class and also has a toArray() method (see here).

Unfortunately, the declarations are incompatible, because Laravel's toArray() doesn't declare a return type. This will generate an error ("Declaration of Illuminate\Http\Request::toArray() must be compatible with Symfony\Component\HttpFoundation\Request::toArray(): array"). Laravel can't easily add the return type to its toArray() because that would break BC for anyone extending the Laravel Request class.

I suggested laravel/framework#34662 as a fix in Laravel, but as @GrahamCampbell noted, that's not ideal either. I realize it isn't really a BC break or bug for Symfony itself, but seeing how many projects (any Laravel 7.x or 8.x project) this would break, maybe we can come up with some kind of solution? Just removing the return type would help.

See laravel/framework#34660, laravel/framework#34662

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