I have two DateTimeImmtable
objects, and expecting them to be identical I am surprised to see they are not. Ie, why is the following false
?
<?php
$d = new \DateTimeImmutable('2018-01-01');
$e = new \DateTimeImmutable('2018-01-01');
var_dump($d === $e);
Of course $d == $e
evaluates to true
It's nothing to do with DateTimeImmutable
objects, it's just how PHP deals with object comparison. From the manual:
When using the identity operator (===), object variables are identical if and only if they refer to the same instance of the same class.
Comparing any two different instances using this operator will always return false, regardless of the values of any properties.