Please don't modify existing instances with date arithmetic methods
kpconnell opened this issue · comments
Krvin commented
Hello,
I encountered an issue with the following code:
$startDate = Carbon::today()->subDays(10);
$endDate = $startDate->addDays(5);
Carbon version: 2.72.3
I expected to get:
a different end date than start date
But I actually get:
end and start date are the same.
Kyle commented
Use CarbonImmutable::today()
instead, it's like DateTime
vs. DateTimeImmutable
. (See the very first chapter of the doc)