PHP Comparing Objects

Posted by Prem Tiwari | Updated on

When using the comparison operator (==), object variables are compared in a simple manner, namely: Two object instances are equal if they have the same attributes and values (values are compared with ==), and are instances of the same class.

When using the identity operator (===), object variables are identical if and only if they refer to the same instance of the same class.

Example #1 Example of object comparison in PHP 5

The above example will output:

Reference: https://www.php.net/manual/en/language.oop5.object-comparison.php


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers