.. _classes-dontunsetproperties: .. _don't-unset-properties: Don't Unset Properties ++++++++++++++++++++++ Don't unset properties. They would go undefined, and raise warnings of undefined properties, even though the property is explicitly defined in the original class. When getting rid of a property, assign it to `null`. This keeps the property defined in the object, yet allows existence check without errors. This analysis works on properties and `static `_ properties. It also reports magic properties being unset. Thanks for `Benoit Burnichon `_ for the original idea. .. code-block:: php null] unset($a->a); var_dump((array) $a) ; //Empty [] // Check if a property exists var_dump($a->b === null); // Same result as above, but with a warning var_dump($a->c === null); ?> Related PHP errors ------------------- + `0 `_ Connex PHP features ------------------- + `property `_ Suggestions ___________ * Set the property to null or its default value * Make the property an array, and set/unset its index Specs _____ +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Short name | Classes/DontUnsetProperties | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`CE `, :ref:`CI-checks `, :ref:`Changed Behavior `, :ref:`Top10 `, :ref:`php-cs-fixable ` | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 1.2.3 | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Severity | Major | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Slow (1 hour) | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Precision | Very high | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Examples | :ref:`case-vanilla-classes-dontunsetproperties`, :ref:`case-typo3-classes-dontunsetproperties` | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Community Edition `_, `Exakat Cloud `_ | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+