Comparing Objects

Objects can be compared using:

 

  • Comparison operator ==
    • Checks if the properties are the same 
  • Identity operator ===
    • Also checks if instances of the same class

This example creates a new object, clones it and then copies the original object using a simple assignment:

Save & refresh browser:

$geek object instantiated. 

 

$geek and $techie objects don't compare.
$geek and $imposter objects compare.
$geek and $techie objects are not identical.
$geek and $imposter objects are identical.

 

Person::__set_state(array(
'name' => 'Will',
'now' => 1372934803,
))

 

Person::__set_state(array(
'name' => 'Will',
'now' => 1372934804,
))

 

Person::__set_state(array(
'name' => 'Will',
'now' => 1372934803,
))

Leave a Reply