Skip to content

Collection->mapInto() does not work as before #56290

@matiss-zalans

Description

@matiss-zalans

Laravel Version

11.45.1

PHP Version

8.2.11

Database Driver & Version

No response

Description

Not sure, but looks like after migrating from version 10.x to 11.x
Collection->mapInto() method is not working as before.
Now I get this error with stack tracing to here.

[2025-07-14 12:59:12] local.ERROR: Too few arguments to function Illuminate\Support\Collection::Illuminate\Support\Traits\{closure}(), 1 passed and exactly 2 expected {"userId":"???","exception":"[object] (ArgumentCountError(code: 0): Too few arguments to function Illuminate\\Support\\Collection::Illuminate\\Support\\Traits\\{closure}(), 1 passed and exactly 2 expected at /var/www/app/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:448)
[stacktrace]
#0 [internal function]: Illuminate\\Support\\Collection->Illuminate\\Support\\Traits\\{closure}()
#1 /var/www/app/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(611): array_map()
#2 /var/www/app/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(802): Illuminate\\Support\\Arr::map()
#3 /var/www/app/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(448): Illuminate\\Support\\Collection->map()
#4 ???? Illuminate\\Support\\Collection->mapInto()

Here in example first line fails, second one - succeeds.

collect([105324996, 105276422])->mapInto(RandomClass::class)->all();
collect([105324996, 105276422])->map(fn($item) => new RandomClass($item))->all();

Here is an example of constructor of the class.

public function __construct(int $userId)
{
    parent::__construct([
        'user_id' => $userId,
        'start_at' => method_1(),
        'expire_at' => method_2(),
    ]);
}

Steps To Reproduce

Not sure. Try to run the mapInto() on some collection of integers and use a custom class to map those values into.

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