self_static_accessor.rst 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. =============================
  2. Rule ``self_static_accessor``
  3. =============================
  4. Inside a ``final`` class or anonymous class ``self`` should be preferred to
  5. ``static``.
  6. Examples
  7. --------
  8. Example #1
  9. ~~~~~~~~~~
  10. .. code-block:: diff
  11. --- Original
  12. +++ New
  13. @@ -5,7 +5,7 @@
  14. public function getBar()
  15. {
  16. - return static::class.static::test().static::$A;
  17. + return self::class.self::test().self::$A;
  18. }
  19. private static function test()
  20. Example #2
  21. ~~~~~~~~~~
  22. .. code-block:: diff
  23. --- Original
  24. +++ New
  25. @@ -3,6 +3,6 @@
  26. {
  27. public function bar()
  28. {
  29. - return new static();
  30. + return new self();
  31. }
  32. }
  33. Example #3
  34. ~~~~~~~~~~
  35. .. code-block:: diff
  36. --- Original
  37. +++ New
  38. @@ -3,6 +3,6 @@
  39. {
  40. public function isBar()
  41. {
  42. - return $foo instanceof static;
  43. + return $foo instanceof self;
  44. }
  45. }
  46. Example #4
  47. ~~~~~~~~~~
  48. .. code-block:: diff
  49. --- Original
  50. +++ New
  51. @@ -2,6 +2,6 @@
  52. $a = new class() {
  53. public function getBar()
  54. {
  55. - return static::class;
  56. + return self::class;
  57. }
  58. };