note 112297 added to language.oop5.object-comparison
| From: | Oddant | Date: | Wed, 29 May 2013 17:15:24 +0000 |
| Subject: | note 112297 added to language.oop5.object-comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194984@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 );
----
Server IP: 69.147.83.199
Probable Submitter: 193.49.30.34
----
Manual Page -- http://php.net/manual/en/language.oop5.object-comparison.php
Edit -- https://master.php.net/note/edit/112297
Del: integrated -- https://master.php.net/note/delete/112297/integrated
Del: useless -- https://master.php.net/note/delete/112297/useless
Del: bad code -- https://master.php.net/note/delete/112297/bad+code
Del: spam -- https://master.php.net/note/delete/112297/spam
Del: non-english -- https://master.php.net/note/delete/112297/non-english
Del: in docs -- https://master.php.net/note/delete/112297/in+docs
Del: other reasons-- https://master.php.net/note/delete/112297
Reject -- https://master.php.net/note/reject/112297
Search -- https://master.php.net/manage/user-notes.php