note 49077 deleted from types.comparisons by nlopess
| From: | nlopess@php.net | Date: | Sun, 16 Jan 2005 10:13:30 +0000 |
| Subject: | note 49077 deleted from types.comparisons by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83421@lists.php.net to get a copy of this message | ||
Note Submitter: phpmanual at derosetechnologies dot com
Reason: useless example
----
I didn't see any encompassing information regarding the effects of the '===' operator
when dealing with object & array() comparisons. Here are some pertinent facts worth
understanding.
NOTE: When dealing with objects
It would seem that this operator will test the provided object's class type, as well as its
member variables.
This example:
<?
class MyClassA {
var $bMember = NULL;
function MyClassA($bMember) {$this->bMember = $bMember;}
}
$objA = new MyClassA(true);
$objB = new MyClassA(false);
echo "These two classes are: ".(($objA === $objB) ? "equal!" : "not
equal!");
?>
produces the output:
These two classes are: not equal!
NOTE: When dealing with arrays:
Identical comparisons ( '===') largely work as you'd expect, only returning true if
the contents of the arrays match exactly. The only inconsistency (depending on how you want to
lookat it) is that you might get caught by however is the following example:
<?
$a_A = array();
$a_A['A'] = 1;
$a_A['B'] = 2;
$a_B = array();
$a_B['B'] = 2;
$a_B['A'] = 1;
echo "These two arrays are: ".(($a_B === $a_B) ? "equal!" : "not
equal!");
?>
which produces the output:
These two arrays are: equal!
The reason this is perhaps inconsistent is because $a_A 's 'internal pointer' is set
to array('A' => 1) , whereas $a_B's 'internal pointer' is set to
array('B' => 2) IMHO, I think this was the most appropriate way of handling the
scenario.