They could just use !!filter_var() or (bool)filter_var() and they wouldn't need the === false part. This would still not solve the integer zero problem, though.
I think the correct way is to do the check is this way :
if(!(filter_var($int, FILTER_VALIDATE_INT)===false)){
echo("Integer is valid");}else{
echo("Integer is not valid");}
Because the rule is that `filter_var' return bool(false) only if there is an invalid integer, else return int(the value). And we test "!(fnc === false)" because the `!`operator take precedence over `===` otherwise.
Why is this expression used in the tutorial?
in PHP
Posted · Edited by Nicos99
I think the correct way is to do the check is this way :
Because the rule is that `filter_var' return bool(false) only if there is an invalid integer, else return int(the value). And we test "!(fnc === false)" because the `!`operator take precedence over `===` otherwise.
More over hese is no integer zero problem anymore
==> What do you think of that ?