no_null_property_initialization.rst 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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>`_
  33. References
  34. ----------
  35. - Fixer class: `PhpCsFixer\\Fixer\\ClassNotation\\NoNullPropertyInitializationFixer <./../../../src/Fixer/ClassNotation/NoNullPropertyInitializationFixer.php>`_
  36. - Test class: `PhpCsFixer\\Tests\\Fixer\\ClassNotation\\NoNullPropertyInitializationFixerTest <./../../../tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php>`_
  37. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.