Skip to content

[DeadCode] Skip on clone on object with __clone() method on RemoveDeadStmtRector#8084

Merged
TomasVotruba merged 3 commits into
mainfrom
skip-clone
Jun 25, 2026
Merged

[DeadCode] Skip on clone on object with __clone() method on RemoveDeadStmtRector#8084
TomasVotruba merged 3 commits into
mainfrom
skip-clone

Conversation

@samsonasik

@samsonasik samsonasik commented Jun 24, 2026

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9785
Ref https://getrector.com/demo/de6a20d5-8b29-473b-86dd-e719f4b435e2

final class DemoFile
{
    public function __clone()
    {
        throw new RuntimeException('clone is not allowed');
    }
}

$obj = new DemoFile();
-clone $obj;

The clone $obj usage is on purpose to show RuntimeException on the example, so should be skipped.

@samsonasik samsonasik requested a review from TomasVotruba June 25, 2026 00:02
@samsonasik

Copy link
Copy Markdown
Member Author

@TomasVotruba ready 👍

@TomasVotruba

Copy link
Copy Markdown
Member

LGTM 👍

@TomasVotruba TomasVotruba merged commit c38a215 into main Jun 25, 2026
67 checks passed
@TomasVotruba TomasVotruba deleted the skip-clone branch June 25, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect behavior of RemoveDeadStmtRector on clone on object with __clone() method

2 participants