mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-2302: entity not updating with existing \Datetime object #2891
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?
Originally created by @doctrinebot on GitHub (Feb 17, 2013).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user stijink:
Within an entity i have an method to add days to a subscription. For that an datetime object is modified.
But the database is not going to be updated if an already existing datetime-object is modified an set. It's only working when an freshly created datetime object is used.
NOT WORKING EXAMPLE:
WORKAROUND:
@doctrinebot commented on GitHub (Feb 17, 2013):
Comment created by @beberlei:
From the documentation (Mapping Objects):
You have to replace them with a new instance.
@doctrinebot commented on GitHub (Feb 17, 2013):
Comment created by stijink:
Whats the reason for this behaviour ? For me it seem not very intuitive and cost me a couple of hours of project time :)
@doctrinebot commented on GitHub (Feb 17, 2013):
Comment created by @ocramius:
[~stijink] there is no real "global" way of comparing objects in PHP. The only way would be to use a non-strict comparison (aka
==vs===), and that leads to many unexpected problems.Since
DateTimeinstances are objects like any other, the comparison is applied with===.This the safest way to handle this is to work with it as if it was an immutable:
This basically disallows a lot of unexpected behaviors, even when not working with the ORM.
@doctrinebot commented on GitHub (Feb 17, 2013):
Comment created by @beberlei:
Also DateTime objects being mutable was a mistake in PHP, this is why 5.5 will have DateTimeImmutable, which we will switch to if possible in the future :)
@doctrinebot commented on GitHub (Sep 8, 2013):
Comment created by @beberlei:
Change to 'Invalid'
@doctrinebot commented on GitHub (Sep 8, 2013):
Issue was closed with resolution "Invalid"