Comparing Objects in PHP4

Comparing Objects in PHP4

=> We can compare two objects with == operator.
=> == operator return true if properties of the objects are same.

Example:
class One {
var $val;

function One($var){
$this->var = $var;
}
}

$objl = new One('num');
$obj2 = new One('num');
$obj3 = new One('num1');

if($objl == $obj2)
echo "Same";
else
echo "Diiferent";

if($objl == $obj3)
echo "Same";
else
echo "Diiferent";

In the above example
if($objl == $obj2) - returns true
because both having the same value for variable $val.
if($objl == $obj3) - returns false
because both having the different values for variable $val.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.