I know which type of variable $value
should be. Should is_numeric()
be used to test whether it is a float string?
private function sanitize($value, $type) {
switch($type) {
case 'boolean':
if(!is_bool($value)) $value=filter_var($value, FILTER_VALIDATE_BOOLEAN);
break;
case 'integer':
if(ctype_digit($value)) $value=(int)$value;
break;
case 'float':
if(is_numeric($value) && !is_float($value)) $value=(float)$value;
break;
//case 'string':case 'object':case 'array': //Not sanitized
}
return $value;
}