For a variable like the following $p = $_GET['page']
In conditions like the following
if ($p > 0)
if ($p < 0)
if ($p >= 0)
if ($p <= 0)
if ($p == 0)
does it work same as
if (ctype_digit($p)){//Logic}
//or...
if (is_numeric($p)){//Logic}
For a variable like the following $p = $_GET['page']
In conditions like the following
if ($p > 0)
if ($p < 0)
if ($p >= 0)
if ($p <= 0)
if ($p == 0)
does it work same as
if (ctype_digit($p)){//Logic}
//or...
if (is_numeric($p)){//Logic}
My suggestion is pass in the right datatype for the job. So if you need number pass that to this code.
If you cannot control what is being passed in then check what it is first. This makes you take a second look when code starts to break. I would use is_numeric
because it know negatives and floats unlike ctype_digit
is_numeric("-10"); //TRUE
ctype_digit("-10"); //FALSE
is_numeric("12.10"); //TRUE
ctype_digit("12.10"); //FALSE
So in the end you would want to do something like:
$p = $_GET['page'];
if(is_numeric($p)){
$p = (int)$p;
//Do stuff with an int
} else {
//Not sure what should happen here...
}
PHP is super flexible with casting for us but when it comes to trying to find a bug in your code it becomes hard to find when you act like everything is coming in good ie if($p>0){}
seems like you know you have a number and I would keep looking elsewhere.