Skip to content

[Php55] Handle own class method reference string in StringClassNameToClassConstantRector - #9066

Merged
TomasVotruba merged 1 commit into
mainfrom
string-class-name-self-method
Nov 25, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
string-class-name-self-method

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

A string pointing to a method of the class it sits in, like a Symfony controller reference, now uses self::class:

 namespace App\Controller;

 final class ClientController
 {
     public function deleteAction()
     {
-        return ['contentTemplate' => 'App\Controller\ClientController::indexAction'];
+        return ['contentTemplate' => self::class . '::indexAction'];
     }
 }
  • only when the class part matches the enclosing class exactly (case-sensitive)
  • skipped in traits and anonymous classes, where self would point elsewhere
  • other classes' Class::method strings are left untouched

Real world case: mautic/mautic#18371

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