<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed May 22 22:19:27 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://doctrine-project.org/jira/si/jira.issueviews:issue-xml/DDC-2302/DDC-2302.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DDC-2302] entity not updating with existing \Datetime object</title>
                <link>http://doctrine-project.org/jira/browse/DDC-2302</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;Within an entity i have an method to add days to a subscription. For that an datetime object is modified.&lt;/p&gt;

&lt;p&gt;But the database is not going to be updated if an already existing datetime-object is modified an set. It&apos;s only working when an freshly created datetime object is used.&lt;/p&gt;

&lt;p&gt;NOT WORKING EXAMPLE:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function addDaysToSubscription($days) {

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasValidSubscription()) {

            $startFromDate = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSubscriptionValidUntil();
        }
        &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {

            $startFromDate = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \DateTime(&apos;now&apos;);
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;setSubscriptionValidUntil($startFromDate-&amp;gt;modify(&apos;+&apos; . $days .&apos; days&apos;));
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;WORKAROUND:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function addDaysToSubscription($days) {

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasValidSubscription()) {

            $validDate = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSubscriptionValidUntil()-&amp;gt;format(&apos;Y-m-d H:i:s&apos;);
            $startFromDate = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \DateTime($validDate);
        }
        &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {

            $startFromDate = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \DateTime(&apos;now&apos;);
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;setSubscriptionValidUntil($startFromDate-&amp;gt;modify(&apos;+&apos; . $days .&apos; days&apos;));
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment>ubuntu 12.04&lt;br/&gt;
PHP 5.3.10&lt;br/&gt;
PostgreSQL 8.4&lt;br/&gt;
Symfony 2.0.15</environment>
            <key id="14489">DDC-2302</key>
            <summary>entity not updating with existing \Datetime object</summary>
                <type id="1" iconUrl="http://doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="stijink">Stephan Tijink</reporter>
                        <labels>
                    </labels>
                <created>Sun, 17 Feb 2013 14:13:57 +0000</created>
                <updated>Sun, 17 Feb 2013 16:20:49 +0000</updated>
                    <resolved>Sun, 17 Feb 2013 15:37:20 +0000</resolved>
                            <version>2.1.7</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="19551" author="beberlei" created="Sun, 17 Feb 2013 15:37:20 +0000"  >&lt;p&gt;From the documentation (Mapping Objects):&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
DateTime and &lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt; types are compared by reference, not by value. Doctrine updates &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; values &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the reference changes and therefore behaves as &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; these objects are immutable value objects.
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You have to replace them with a new instance.&lt;/p&gt;</comment>
                    <comment id="19552" author="stijink" created="Sun, 17 Feb 2013 15:46:17 +0000"  >&lt;p&gt;Whats the reason for this behaviour ? For me it seem not very intuitive and cost me a couple of hours of project time &lt;img class=&quot;emoticon&quot; src=&quot;http://doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                    <comment id="19553" author="ocramius" created="Sun, 17 Feb 2013 15:56:00 +0000"  >&lt;p&gt;&lt;a href=&quot;http://doctrine-project.org/jira/secure/ViewProfile.jspa?name=stijink&quot; class=&quot;user-hover&quot; rel=&quot;stijink&quot;&gt;Stephan Tijink&lt;/a&gt; there is no real &quot;global&quot; 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.&lt;/p&gt;

&lt;p&gt;Since `DateTime` instances are objects like any other, the comparison is applied with `===`. &lt;/p&gt;

&lt;p&gt;This the safest way to handle this is to work with it as if it was an immutable:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
&lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setCreationTime(\DateTime $dateTime)
{
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;creationTime = clone $dateTime;
}

&lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getCreationTime(\DateTime $dateTime)
{
    &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; clone $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;creationTime;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This basically disallows a lot of unexpected behaviors, even when not working with the ORM.&lt;/p&gt;</comment>
                    <comment id="19554" author="beberlei" created="Sun, 17 Feb 2013 16:20:46 +0000"  >&lt;p&gt;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 &lt;img class=&quot;emoticon&quot; src=&quot;http://doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>