Skip to content

StrvalToTypeCastRector crash with variadic param #7970

Description

@NicoImparfait

Bug Report

Subject Details
Rector version e.g. v0.17.0 (invoke vendor/bin/rector --version)

Rector crash due to StrvalToTypeCastRector when using strval with variadic param

https://getrector.com/demo/bbbf6bbc-d903-4940-ae03-7b06782ffcde

  • on version 0.17.0 I have the following error:
"System error: "PhpParser\Node\Expr\Cast::__construct(): Argument #1 ($expr) must be of type
         PhpParser\Node\Expr, null given, called in
         vendor/rector/rector/rules/CodeQuality/Rector/FuncCall/StrvalToTypeCastRector.php57"

  • from getrector (commit 7cde41), I have the following error:
"System error: "Undefined property: PhpParser\Node\VariadicPlaceholder::$value"

Minimal PHP Code Causing Issue

<?php

final class DemoFile
{
    public function run()
    {
      return array_map(strval(...), [1, 2, 3]);
    }
}

Expected Behaviour

<?php

final class DemoFile
{
    public function run()
    {
          return array_map(fn($arg) => (string) $arg, [1, 2, 3]);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions