I know the comparison operator of PHP is not 100% because of the automatic type declarations.
I did some tests and found this code
<?php
function foo($answer) {
if ($answer > 10) {
return true;
} else {
return $answer;
}
}
if (foo(11)) {
echo "11 is bigger than 10<br />";
}
if (foo(9)) {
echo "9 is bigger than 10<br />";
}
?>
The output is:
11 is bigger than 10
9 is bigger than 10
Can someone explain me where and why the code fails in this comparison.
Function
foo()always returns some value. In this case both boolean and int type. Just make sure you are more strictly when you compare returned value.