Dates overwriting one another in php
<p>Okay, so I'm trying to get two variables. One with yesterday's date, one with a date six days from today. This is so I can query google calendar for events happening this week.
I'm building a date time object, setting the date to today, then trying to store the values in two new variables. However, when I set the second variable, the first is getting modified as well. It appears to be assigning the variables by a reference to the object instead of the value I'm trying to stick into it.</p>

<pre><code>$todayData = explode("-", date("Y-m-d", Time()));
//Get DateTime for Yesterday
$today = new DateTime();
$today-&gt;setDate($todayData[0], $todayData[1], $todayData[2]);
echo $today-&gt;format("Y-m-d");
echo "&lt;br /&gt;";
//Yesterday
$startDate = $today-&gt;modify("-1 day");
echo $startDate-&gt;format("Y-m-d");
echo "&lt;br /&gt;";
//End of the week
$endDate = $today-&gt;modify("+6 day");
echo $endDate-&gt;format("Y-m-d");
echo "&lt;br /&gt;";

//recheck yesterday
echo $startDate-&gt;format("Y-m-d");
</code></pre>
