no_unset_on_property.rst 865 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. =============================
  2. Rule ``no_unset_on_property``
  3. =============================
  4. Properties should be set to ``null`` instead of using ``unset``.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Risky when relying on attributes to be removed using ``unset`` rather than be
  10. set to ``null``. Changing variables to ``null`` instead of unsetting means these
  11. still show up when looping over class variables and reference properties remain
  12. unbroken. With PHP 7.4, this rule might introduce ``null`` assignments to
  13. properties whose type declaration does not allow it.
  14. Examples
  15. --------
  16. Example #1
  17. ~~~~~~~~~~
  18. .. code-block:: diff
  19. --- Original
  20. +++ New
  21. <?php
  22. -unset($this->a);
  23. +$this->a = null;
  24. Rule sets
  25. ---------
  26. The rule is part of the following rule set:
  27. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_