Skip to content

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

Merged
TomasVotruba merged 1 commit into
mainfrom
string-class-own-class-to-self
Nov 26, 2026
Merged

TomasVotruba merged 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.

@TomasVotruba
TomasVotruba merged commit 4aef04e into main Nov 26, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the string-class-own-class-to-self branch November 26, 2026 16:58
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