Skip to content

Incorrect array shape using splat (...) in array_push #5783

@leongersen

Description

@leongersen

Bug report

I ran into this while creating an example for another report. When "merging" arrays using array_push and the splat operator, the resulting array shape is not complete.

Code snippet that reproduces the problem

https://phpstan.org/r/13388f61-19fe-4046-81c2-24f438783242

$a = [new HelloWorld()];
$b = [new HelloWorld(), new HelloWorld(), new HelloWorld()];

array_push($a, ...$b);

This produces the following as the type for $a:

array{HelloWorld, HelloWorld}

Expected output

array{HelloWorld, HelloWorld, HelloWorld, HelloWorld}

or

array<HelloWorld>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions