# Are all PHP equality comparisons reflexive?

Is `\$a == \$b` always equivalent to `\$b == \$a`?

I think in JavaScript there's a few weird cases where that's not true, due to casting.

I think ide is correct. I'll ask another question.

I would say 'reflexive'.

@Joe: Thanks. Updated.

@Joe is correct. This is considered reflexivity. Associativity is when `(A + B) + C = A + (B + C)`

Don't quote me on this, but I think the weird cases arise for transitivity; i.e., `a == b` and `b == c` but `a != c`.

I have tried a number of variations and cannot find a case where `(\$a == \$b) !== (\$b == \$a)`, but I am determined to do so now!

@ide: Oh... is that where it occurs? Maybe I should have asked that instead then :)

Depends what happens between those two calls. Otherwise yes, those are the same. The order makes no difference. Using 2 equals `==` A string of 1 and integer of 1, will return true when compared. Type is ignored, only value is compared. So no wierdness.

http://php.net/manual/en/language.operators.comparison.php

``````<?

\$a=(string) 1;
\$b=(int) 1;

var_dump(\$a);
var_dump(\$b);

echo \$a==\$b;
``````

Outputs: 1

http://www.ideone.com/JLJWQ

EDIT

To clarify, there is absolutely nothing you can ever put in \$a or \$b to get a different output on the comparison, just by putting it on the other side of the operator.

``````\$a="1234";
\$b="1234";

echo \$a==\$b;
echo \$b==\$a;
``````

The output of that, for any \$a or \$b values, will always without a doubt be true true, or false false.

This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.