note 112297 modified in language.oop5.object-comparison by danbrown

From: Date: Wed, 05 Jun 2013 17:40:43 +0000
Subject: note 112297 modified in language.oop5.object-comparison by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-195064@lists.php.net to get a copy of this message
This example is way too much confusing, if you new to php comparison motor, you should think (after reading this example) that '==' is actually comparing the type of the objects. that's not true, it actually compares the type of the objects AND the properties of them. <?php class A { private $value; function __construct ($value) { $this->value = $value; } } class B { private $value; function __construct ($value) { $this->value = $value; } } $a1 = new A (1); $a2 = new A (2); $b1 = new B (1); var_dump( $a1 == $a2 ); var_dump( $a1 == $b1 ); ?> --was-- This example is way too much confusing, if you new to php comparison motor, you should think (after reading this example) that '==' is actually comparing the type of the objects. that's not true, it actually compares the type of the objects AND the properties of them. <?php class A { private $value; function __construct ($value) { $this->value = $value; } } class B { private $value; function __construct ($value) { $this->value = $value; } } $a1 = new A (1); $a2 = new A (2); $b1 = new B (1); var_dump( $a1 == $a2 ); var_dump( $a1 == $b1 ); http://php.net/manual/en/language.oop5.object-comparison.php

« previous php.notes (#195064) next »