As far as I know, PHP compares two objects only by looking at their properties indefinitely to the end.
if ($ node1 == $ node2)
$node1 == $node2? if $node1 -> next == $node2->next if $node1->next(node2)->next == $node2->next(node1)->next if $node1->next(node2)->next(node1)->next == $node2->next(node1)->next(node2)->next;
Infinitely...
If an object has a property, it will look at them if you are comparing two objects.
So why does your rigorous comparison work, because it just checks to see if two objects are in the same place in memory , and therefore it doesn't even look at the values ββof the properties.
if ($ node1-> next == $ node2)
Why compare if ($ node1-> next == $ node2) , I think, as shown below: PHP first compares the "address" if the two objects to be compared have the same address. PHP assumes that they must be identical because they are in the same place .
Like $ node1 has address 1. And $ node2 has address 2. $ node2-> next then have address 1. The same address, PHP does not want to view the properties now, because they are in the same place.
Also for your reference. The comparison result "==" and "===" respectively on php.net http://php.net/manual/en/language.oop5.object-comparison.php
Two instances of the same class o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : FALSE o1 !== o2 : TRUE Two references to the same instance o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : TRUE o1 !== o2 : FALSE Instances of two different classes o1 == o2 : FALSE o1 != o2 : TRUE o1 === o2 : FALSE o1 !== o2 : TRUE
source share