no_null_property_initialization.rst 742 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ========================================
  2. Rule ``no_null_property_initialization``
  3. ========================================
  4. Properties MUST not be explicitly initialized with ``null`` except when they
  5. have a type declaration (PHP 7.4).
  6. Examples
  7. --------
  8. Example #1
  9. ~~~~~~~~~~
  10. .. code-block:: diff
  11. --- Original
  12. +++ New
  13. <?php
  14. class Foo {
  15. - public $foo = null;
  16. + public $foo;
  17. }
  18. Example #2
  19. ~~~~~~~~~~
  20. .. code-block:: diff
  21. --- Original
  22. +++ New
  23. <?php
  24. class Foo {
  25. - public static $foo = null;
  26. + public static $foo;
  27. }
  28. Rule sets
  29. ---------
  30. The rule is part of the following rule sets:
  31. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  32. - `@Symfony <./../../ruleSets/Symfony.rst>`_