Is it safe to assume that in
if (($i = (int)trim($_GET['user_input'])) != 0) {
// do stuff with $i
}
$i
can only ever be an integer?
Edit:
I now use:
if (ctype_digit($i = $_GET['user_input'])) {
// do stuff with $i
}
Is it safe to assume that in
if (($i = (int)trim($_GET['user_input'])) != 0) {
// do stuff with $i
}
$i
can only ever be an integer?
Edit:
I now use:
if (ctype_digit($i = $_GET['user_input'])) {
// do stuff with $i
}
So if your only question is if it's in any case a int
, then is the answer :
Yes
But if the cast to int fails (e.g. input: 'a'
) $i
is just 0
Example:
Input/ Output:
4 -> 4
-5 -> -5
"14" -> 15
"a" -> 0
"!" -> 0
array() -> 0
Side Note:
If the value is an array trim fails and you get an error