October 23, 2025

How fucked is PHP?

How fucked is PHP?

If you thought that something was fucked up, you haven't seen the new, oh, so wonderful PHP DateTime and DateInterval interfaces. They will blow your mind.

$date = new DateTime(); // "2025-10-23 16:38:25.308372"
var_dump($date);

$interval = new DateInterval("PT30M");
var_dump($interval);

$newdate = $date->add($interval);
var_dump($newdate); // "2025-10-23 17:08:25.308372" - 30 min later

if($date == $newdate) echo "Equal"; // Prints 'Equal' - why?
$diff = $date->diff($newdate);
var_dump($diff); // All zeros - why?

echo $diff->format('%r%i'); // 0 - why?
echo $diff->format('%r%s'); // 0 - why?

$diff = $newdate->diff($date);
var_dump($diff); // All zeros - why?

echo $diff->format('%r%i'); // 0 - why?
echo $diff->format('%r%s'); // 0 - why?

So, we have two date/times, 30 minutes apart, but according to PHP they are equal.

I wasted almost 2 hours on this shit, trying to figure out if something in my code has expired or not. I can do this in C#, Java, TSQL, MySQL, all in a matter of a few seconds. In PHP? Nope. No soup for you, PHP developers. The collective won't let you know the difference between to date/times.

PS: And if you replace DateTime() with DateTimeImmutable(), then you will see the correct 30 min difference but still 0 second difference. What's this obsession with immutability where no one gives a fuck?

Posted by: LinuxLies at 04:05 PM | No Comments | Add Comment
Post contains 216 words, total size 1 kb.




What colour is a green orange?




16kb generated in CPU 0.0117, elapsed 0.0277 seconds.
35 queries taking 0.0208 seconds, 148 records returned.
Powered by Minx 1.1.6c-pink.