Comparing Objects with == and === : Objects « Class « PHP






Comparing Objects with == and ===

 
<?php
    class Employee { }

    $Bob = new Employee( );
    $Joe = clone $Bob;

    print (int)($Bob == $Joe) . "\n";
    print (int)($Joe === $Joe) . "\n";

    class Employee {
            public function __construct( ) {
                    $this->myself = $this;
            }
    }

    $Bob = new Employee( );
    $Joe = clone $Bob;

    print (int)($Bob == $Joe) . "\n";
    print (int)($Bob === $Joe) . "\n";
    
?>
  
  








Related examples in the same category

1.Create a new class and create an instance then use its property and method
2.Object Initialization
3.Object Overloading
4.Object Properties
5.Object Type Information
6.Objects Within Objects
7.Creating a new object and assigning it to a variable