In JavaScript, the ==
operator isn\'t necessarily transitive:
js> \'0\' == 0
true
js> 0 == \'\'
true
js> \'0\' == \'\'
false
The same is true in PHP:
//php
'0'==0 //true
0=='' //true
''=='0' //false
Did you not test it yourself? These are the same statements you provided for javascript.
No, the ==
operator is not transitive.
The exact same scenario gives the same result in PHP.
echo var_dump('0'==0);
echo var_dump(0=='');
echo var_dump('0'=='');
yields:
boolean true
boolean true
boolean false
array() == NULL // true
0 == NULL // true
array() == 0 // false
The problem with scripting languages is that we start comparing things in a non-strict way, which leads to different senses of "equality." when you are comparing "0" and 0, you mean something different then when you are comparing "0" and NULL. Thus it makes sense that these operators would not be transitive. Reflexivity however, should be an invariant. Equality is by definition reflexive. No matter what sense you mean equality, it should always be true that A equals itself.
another more obvious one:
true == 1 // true
true == 2 // true
1 == 2 // false