Skip to content

[Php55] Use self::class for own class name string in StringClassNameToClassConstantRector - #9070

Open
TomasVotruba wants to merge 1 commit into
mainfrom
string-class-own-class-to-self
Open

TomasVotruba wants to merge 1 commit into
mainfrom
string-class-own-class-to-self

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #9066. A string naming the class it sits in now becomes self::class, consistent with the method reference handling:

 namespace App;

-#[SomeAttribute('App\SomeClass')]
+#[SomeAttribute(self::class)]
 final class SomeClass
 {
-    public const NAME = 'App\SomeClass';
+    public const NAME = self::class;
 }
  • skipped in traits and anonymous classes, where self points elsewhere, those keep \Fqcn::class
  • covers class attributes, constants and param defaults, self::class is valid in all of them

Until now this needed an extra PHP-CS-Fixer SelfAccessorFixer pass after Rector.

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