Skip to content

[DowngradePhp70] Add DowngradeMethodCallOnCloneRector #6889

Closed
rectorphp/rector-src
#1554
@samsonasik

Description

@samsonasik

Feature Request

Given the following code:

class A
{
    public function run()
    {
        (clone $this)->execute();
    }
    
    public function execute()
    {
        echo 'test';
    }
}

On php 5.6, it will got error:

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR)

ref https://3v4l.org/ATBe3#v5.6.40

with DowngradeLevelSetList::DOWN_TO_PHP_56, it currently skipped,

The expected change code is:

-        (clone $this)->execute();
+        $object = clone $this;
+        $object->execute();

ref https://3v4l.org/kIeY1#v5.6.40

Repository demo for this https://github.com/samsonasik/test-php56

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