ternary_to_null_coalescing.rst 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ===================================
  2. Rule ``ternary_to_null_coalescing``
  3. ===================================
  4. Use ``null`` coalescing operator ``??`` where possible.
  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 <./../../ruleSets/PHP70Migration.rst>`_
  19. - `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_
  20. - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_
  21. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_
  22. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_
  23. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_
  24. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_
  25. - `@PHP83Migration <./../../ruleSets/PHP83Migration.rst>`_
  26. - `@PHP84Migration <./../../ruleSets/PHP84Migration.rst>`_
  27. References
  28. ----------
  29. - Fixer class: `PhpCsFixer\\Fixer\\Operator\\TernaryToNullCoalescingFixer <./../../../src/Fixer/Operator/TernaryToNullCoalescingFixer.php>`_
  30. - Test class: `PhpCsFixer\\Tests\\Fixer\\Operator\\TernaryToNullCoalescingFixerTest <./../../../tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php>`_
  31. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.