
PHP's weird Comparisons - sandreas
We all know that PHP&#x27;s comparisons my feel kind of weird but at least i thought it would follow some reasonable rules.<p>Recently i came across some comparisons, that may follow rules, but make me feel really uncomfortable using the == operator, when comparing strings:<p><pre><code>  &#x2F;&#x2F; true
  var_dump(&quot;+09&quot;==&quot;009&quot;);
  var_dump(&quot;  09&quot;==&quot;009&quot;);
  var_dump(&quot;  -09&quot;==&quot;-009&quot;);
  var_dump(&quot;\t-09&quot;==&quot;-009&quot;);
  var_dump(&quot;\t\n-09&quot;==&quot;-009&quot;);
  var_dump(&quot;+0&quot;==&quot;-0&quot;);
  var_dump(&quot;09&quot;==&quot;009&quot;);
  var_dump(&quot;9&quot;==&quot;009&quot;);
  
  &#x2F;&#x2F; false
  var_dump(&quot;+  09&quot;==&quot;009&quot;);
  var_dump(&quot;- 09&quot;==&quot;-009&quot;);
</code></pre>
Keep in mind: I am comparing strings, NOT numbers.
======
luckylion
You're really just comparing thingies as interpreted by PHP, not strings. If
you want to compare strings, use ===.

~~~
sandreas
Yeah thx, I already knew === but i still think it is strange behaviour :-)

