Fork me on GitHub
a Sensio Labs Product

I ate three cookies πŸͺ (v3.40.2) edition

Rule no_unset_on_propertyΒΆ

Properties should be set to null instead of using unset.

WarningΒΆ

Using this rule is riskyΒΆ

Risky when relying on attributes to be removed using unset rather than be set to null. Changing variables to null instead of unsetting means these still show up when looping over class variables and reference properties remain unbroken. With PHP 7.4, this rule might introduce null assignments to properties whose type declaration does not allow it.

ExamplesΒΆ

Example #1ΒΆ

--- Original
+++ New
 <?php
-unset($this->a);
+$this->a = null;

Rule setsΒΆ

The rule is part of the following rule set:

Source classΒΆ

PhpCsFixer\Fixer\LanguageConstruct\NoUnsetOnPropertyFixer