Fork me on GitHub
a Sensio Labs Product

7th Gear (v3.57.2) edition

Rule self_accessor

Inside class or interface element self should be preferred to the class name itself.


Using this rule is risky

Risky when using dynamic calls like get_called_class() or late static binding.


Example #1

--- Original
+++ New
 class Sample
     const BAZ = 1;
-    const BAR = Sample::BAZ;
+    const BAR = self::BAZ;

     public function getBar()
-        return Sample::BAR;
+        return self::BAR;

Rule sets

The rule is part of the following rule sets:


The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.