.. _php-datetimenotimmutable: .. _datetimeimmutable-is-not-immutable: DateTimeImmutable Is Not Immutable ++++++++++++++++++++++++++++++++++ ``DateTimeImmutable`` is not really immutable because its internal state can be modified after instantiation. Inspired by the article from ``Matthias Noback``. .. code-block:: php getTimestamp() . "\n"; $dt->__construct('tomorrow'); echo $dt->getTimestamp() . "\n"; ?> See also `Effective immutability with PHPStan `_. Suggestions ___________ * Remove the call to the constructor after instantation of a DateTimeImmutable object Specs _____ +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Short name | Php/DateTimeNotImmutable | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`Changed Behavior ` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 2.4.5 | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Precision | High | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+-------------------------------------------------------------------------------------------------------------------------+