Skip to content

Invalid downgrade code for DowngradeArraySpreadRector on use property + variable same name with different type #9951

Closed
rectorphp/rector-downgrade-php
#422

Description

@samsonasik

Bug Report

Subject Details
Rector version e.g. dev-main (invoke vendor/bin/rector --version)

Minimal PHP Code Causing Issue

Given the following code:

namespace App;

use ArrayIterator;

final class PropertySameNameAsVariable
{
    public ArrayIterator $items;

    public function run()
    {
        $items = ['apple'];

        return [...$this->items, ...$items];
    }
}

$a = new PropertySameNameAsVariable();
$a->items = new ArrayIterator([]);
$a->run();

It produce:

-        return [...$this->items, ...$items];
+        return array_merge($this->items, $items);

see demo page:

which invalid, as it will cause error on run, see

Expected Behaviour

-        return [...$this->items, ...$items];
+        return array_merge(iterator_to_array($this->items), $items);

Activity

  1. changed the title [-]Invalid downgrade code for DowngradeArraySpreadRector on use property + variable same name[/-] [+]Invalid downgrade code for DowngradeArraySpreadRector on use property + variable same name with different type[/+] on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions