Return to Snippet

Revision: 21009
at December 1, 2009 19:38 by chrisaiv


Initial Code
<?php

class Box{
	public $name = "box";
}

$box = new Box();
$box_reference = $box;
$box_clone = clone $box;

$box_changed = clone $box;
$box_changed->name = "changed box";

$another_box = new Box();

// Attributes are pretty much the same
echo $box == $box_reference ? 'true' : 'false'; 
echo "<br />";
echo $box == $box_clone ? 'true' : 'false'; 
echo "<br />";
echo $box == $box_changed ? 'true' : 'false'; 
echo "<br />";
echo $box == $another_box ? 'true' : 'false'; 
echo "<br />";
echo "<br />";
// Checks to see if they reference the same object
echo $box === $box_reference ? 'true' : 'false'; 
echo "<br />";
echo $box === $box_clone ? 'true' : 'false'; 
echo "<br />";
echo $box === $box_changed ? 'true' : 'false'; 
echo "<br />";
echo $box === $another_box ? 'true' : 'false'; 
echo "<br />";

?>

Initial URL

                                

Initial Description
Here are a few examples that show how the relationship between objects and references

Initial Title
PHP: Comparing Objects using == and ===

Initial Tags
php

Initial Language
PHP