self_accessor.rst 828 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ======================
  2. Rule ``self_accessor``
  3. ======================
  4. Inside class or interface element ``self`` should be preferred to the class name
  5. itself.
  6. Warning
  7. -------
  8. Using this rule is risky
  9. ~~~~~~~~~~~~~~~~~~~~~~~~
  10. Risky when using dynamic calls like get_called_class() or late static binding.
  11. Examples
  12. --------
  13. Example #1
  14. ~~~~~~~~~~
  15. .. code-block:: diff
  16. --- Original
  17. +++ New
  18. <?php
  19. class Sample
  20. {
  21. const BAZ = 1;
  22. - const BAR = Sample::BAZ;
  23. + const BAR = self::BAZ;
  24. public function getBar()
  25. {
  26. - return Sample::BAR;
  27. + return self::BAR;
  28. }
  29. }
  30. Rule sets
  31. ---------
  32. The rule is part of the following rule sets:
  33. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_
  34. - `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_