Skip to content

Infinite recursion on array_splice #13279

@arjenm

Description

@arjenm

Bug report

phpstan 2.1.18 crashes with an out-of-memory or with --xdebug (and a sufficiently high memory limit) this error:

Internal error: Maximum call stack size of 8339456 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached.

The callstack is from the phar-version, so I assume the line numbers don't exactly match the source code (it seems ConstantArrayType::spliceArray has an endless recursion, but the line numbers don't match 2.1.18 version on github).
callstack.txt

Code snippet that reproduces the problem

I can't create a reproducer-link on the playground, because that also crashes. But I managed to simplify the code to just this small snippet:

class ReproduceMe
{
    public function crashIt(string $addMe = ''): string
    {
        $arg = [];
        if ($addMe !== '') {
            $arg[] = $addMe;
        }

        array_splice($arg, 'extra', 1);

        return implode(' ', $arg);
    }
}

Expected output

It should not crash

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions