mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[PR #8328] Infer datetime_immutable DBAL type for \DateTimeImmutable instance parameters
#10923
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Original Pull Request: https://github.com/doctrine/orm/pull/8328
State: closed
Merged: Yes
The support for passing
\DateTimeImmutableinstance as a query parameter has been added to ORM in #1333 (the year 2015), a long time before immutable date types (datetime_immutableetc) were introduced to DBAL in doctrine/dbal#2450 (2017).Back then, it made sense to treat
\DateTimeImmutable(or any\DateTimeInterface) in the same way as\DateTimeand infer parameter type asdatetime. However, when immutable date types were later added to DBAL, it wasn't reflected anyhow in type inference in ORM and\DateTimeImmmutableinstances are still inferred asdatetimeDBAL type.This PR fixes this IMO incorrect behaviour of
ParameterTypeInferer::inferType(): for a\DateTimeImmmutableparameter, it now returnsdatetime_immutableDBAL type; for\DateTimeor any other types implementing\DateTimeInterface, it returnsdatetimeDBAL type as it did before.This behaviour is in line with
DateTimeImmutableTypehandling only\DateTimeImmutableandDateTimeTypehandling any\DateTimeInterface.Why? In most cases, it doesn't matter and
datetimeworks for\DateTimeImmutableparameters just fine. But it does matter if using custom implementation ofdatetime_immutabletype likeUTCDateTimeImmutableTypefrom simpod/doctrine-utcdatetime. Then the broken type inference is revealed.This is partially related to #6443, however, this PR isn't about custom DBAL types but about correct type inference for build-in types.