Mittwoch, 24. Februar 2010

("php" == 0) is true

Believe it or not but this is a feature of the language.

http://www.php.net/manual/en/types.comparisons.php
(look for the second table)

PHP automatically casts strings to number, if the boolean expression contains a number or both of the strings are containing only numbers.

So the expression ("01" == "1") is also true,
but ("0" == "php") is false.

You could use strict equal(===) to avoid this behaviour.
Which is a good idea, if you compare different types
or strings with numeric content.

You can't compare apples with oranges, because they are allways different.
But with php you can do it and even better they are equal...;-)

Labels: