Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It appears the usage of "first" or "last" directly in the constructor of the DateTime object causes it to become immutable. This does seem like a bug.</p> <p>e.g.</p> <pre class="lang-php prettyprint-override"><code>date_default_timezone_set('Europe/London'); ini_set('display_errors', 1); error_reporting(E_ALL); $interval = new DateInterval('P1D'); $date1 = new DateTime('last day of this month'); var_dump($date1); $date1-&gt;add($interval); var_dump($date1); echo "-------------------------------\n\n"; $lastDayOfMonth = date('Y-m-d H:i:s', strtotime('last day of this month')); $date2 = new DateTime($lastDayOfMonth); var_dump($date2); $date2-&gt;add($interval); var_dump($date2); echo "-------------------------------\n\n"; $date3 = new DateTime('2012-01-31 '.date('H:i:s')); var_dump($date3); $date3-&gt;add($interval); var_dump($date3); </code></pre> <p>Results in:</p> <pre class="lang-none prettyprint-override"><code>object(DateTime)[2] public 'date' =&gt; string '2012-01-31 11:40:10' (length=19) public 'timezone_type' =&gt; int 3 public 'timezone' =&gt; string 'Europe/London' (length=13) object(DateTime)[2] public 'date' =&gt; string '2012-01-31 11:40:10' (length=19) public 'timezone_type' =&gt; int 3 public 'timezone' =&gt; string 'Europe/London' (length=13) ------------------------------- object(DateTime)[3] public 'date' =&gt; string '2012-01-31 11:40:10' (length=19) public 'timezone_type' =&gt; int 3 public 'timezone' =&gt; string 'Europe/London' (length=13) object(DateTime)[3] public 'date' =&gt; string '2012-02-01 11:40:10' (length=19) public 'timezone_type' =&gt; int 3 public 'timezone' =&gt; string 'Europe/London' (length=13) ------------------------------- object(DateTime)[4] public 'date' =&gt; string '2012-01-31 11:40:10' (length=19) public 'timezone_type' =&gt; int 3 public 'timezone' =&gt; string 'Europe/London' (length=13) object(DateTime)[4] public 'date' =&gt; string '2012-02-01 11:40:10' (length=19) public 'timezone_type' =&gt; int 3 public 'timezone' =&gt; string 'Europe/London' (length=13) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload