I'm confused the following throws an exception:
if (!filter_var(0, FILTER_VALIDATE_INT))
throw new Exception("Non numeric field passed " . $field . " when expecting a number: " . $variable . " passed instead");
anything positive works fine? I've tried intval(0) and still nothing. is zero not an integer?
People should test false instead:
if (filter_var($value, FILTER_VALIDATE_INT) === false) {
// $value is not an integer
}
filter_var Returns the filtered data, or FALSE if the filter fails.
filter_var(0, FILTER_VALIDATE_INT)
returns int(0)
, and is a falsy value, !filter_var(0, FILTER_VALIDATE_INT)
will be true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With