2 ms·
> The only correct ways to verify that a variable contains either a valid numeric string or integer is by comparing type, and then using a regex or a double str
by stephenr 10y ago
> The only correct ways to verify that a variable contains either a valid numeric string or integer is by comparing type, and then using a regex or a double string-then-int cast.
You know there is an entire extension dedicated to validating and sanitising inputs right?
All your type checking and regexes and double cast comparisons could be replaced with:
if (($value = filter_var($value, FILTER_VALIDATE_INT)) !== false) { doStuff(); }
> You could try to blame PHP, but really it's the developers
At least we can agree on one thing.