Values & References12 / 16
Up next

Comparing objects

<?php
declare(strict_types=1);
class P {
    public function __construct(public int $x) {}
}
$a = new P(1);
$b = new P(1);
$c = $a;
// == is true for the same class with equal properties
var_dump($a == $b);
// === is true only for the very same instance
var_dump($a === $b);
var_dump($a === $c);
What you're solving

== equal contents, === same instance