get_class_to_class_keyword.rst 815 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ===================================
  2. Rule ``get_class_to_class_keyword``
  3. ===================================
  4. Replace ``get_class`` calls on object variables with class keyword syntax.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Risky if the ``get_class`` function is overridden.
  10. Examples
  11. --------
  12. Example #1
  13. ~~~~~~~~~~
  14. .. code-block:: diff
  15. --- Original
  16. +++ New
  17. <?php
  18. -get_class($a);
  19. +$a::class;
  20. Example #2
  21. ~~~~~~~~~~
  22. .. code-block:: diff
  23. --- Original
  24. +++ New
  25. <?php
  26. $date = new \DateTimeImmutable();
  27. -$class = get_class($date);
  28. +$class = $date::class;
  29. Rule sets
  30. ---------
  31. The rule is part of the following rule sets:
  32. - `@PHP80Migration:risky <./../../ruleSets/PHP80MigrationRisky.rst>`_
  33. - `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_