Skip to content

[Php83] Require parent class in RemoveGetClassGetParentClassNoArgsRector - #9037

Closed
TomasVotruba wants to merge 1 commit into
mainfrom
get-parent-class-require-parent
Closed

TomasVotruba wants to merge 1 commit into
mainfrom
get-parent-class-require-parent

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

RemoveGetClassGetParentClassNoArgsRector rewrote get_parent_class() to parent::class even in a class without a parent, and get_class() to self::class outside any class:

class Fixture
{
    public function test()
    {
-       echo get_parent_class();
+       echo parent::class;
    }
}

The original prints false, the result is Fatal error: Cannot use "parent" when current class scope has no parent.

Fix - only rewrite inside a class scope, and for get_parent_class() require the class to have a parent. The existing fixture now extends a Source parent class, and skip fixtures cover the no-parent and outside-class cases.

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.

1 participant