Skip to content

Replace DateTime with DateTimeImmutable where possible #7792

@alexander-schranz

Description

@alexander-schranz

Problem description

Currently we are using in a lot of places still DateTime object. DateTime object is mutable. Which means I can call $someObject->getCreated()->modify('+1 day') to modify maybe accidently the created or changed date of a entity.

Proposed solution

For safer code and avoid accidently changing datetimes from outside we should where possible migrate the Entities to DateTimeImmutable.

<field name="created" type="datetime" />
<field name="created" type="datetime_immutable" />

The TimestampableInterface and TimestampableTrait should also be replaced and its metadatalistener. Maybe we should check over the whole code base where it make sense.

Specific functions which require currently a DateTime may should use the DateTimeInterface like we adopted already here: #7702

Metadata

Metadata

Labels

FeatureNew functionality not yet included in Sulu

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions