ternary_to_null_coalescing.rst 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ===================================
  2. Rule ``ternary_to_null_coalescing``
  3. ===================================
  4. Use ``null`` coalescing operator ``??`` where possible. Requires PHP >= 7.0.
  5. Examples
  6. --------
  7. Example #1
  8. ~~~~~~~~~~
  9. .. code-block:: diff
  10. --- Original
  11. +++ New
  12. <?php
  13. -$sample = isset($a) ? $a : $b;
  14. +$sample = $a ?? $b;
  15. Rule sets
  16. ---------
  17. The rule is part of the following rule sets:
  18. @PHP70Migration
  19. Using the `@PHP70Migration <./../../ruleSets/PHP70Migration.rst>`_ rule set will enable the ``ternary_to_null_coalescing`` rule.
  20. @PHP71Migration
  21. Using the `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_ rule set will enable the ``ternary_to_null_coalescing`` rule.
  22. @PHP73Migration
  23. Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``ternary_to_null_coalescing`` rule.
  24. @PHP74Migration
  25. Using the `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ rule set will enable the ``ternary_to_null_coalescing`` rule.
  26. @PHP80Migration
  27. Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``ternary_to_null_coalescing`` rule.
  28. @PHP81Migration
  29. Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``ternary_to_null_coalescing`` rule.
  30. @PHP82Migration
  31. Using the `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_ rule set will enable the ``ternary_to_null_coalescing`` rule.