In the method validateType
it will call the method intgerValidation
why is this giving me a blank page? When I try to run it but when I remove the intgerValidation
method it works?
public function validateType($validateThis, $validationType) {
$validateThis;
$validationType;
if($validationType == 'int') {
$this->integerValidation($validateThis));
}
if($validationType == 'string') {
echo 'Is String';
}
if($valida开发者_StackOverflowtionType == 'email') {
echo 'Is an Email';
}
}
public function integerValidation($int) {
$regex = "/^[0-9]{10}$/";
if(preg_match($regex, $int)) {
return true;
}
else {
return false;
}
}
if($this->validateType(1234567890, 'int')) {
echo 'Hello';
}
else {
echo 'Number does not validate';
}
PHP already have builtin functions for checking variable type
- is_array
- is_bool
- is_callable
- is_double
- is_float
- is_int
- is_integer
- is_long
- is_null
- is_numeric
- is_object
- is_real
- is_resource
- is_scalar
- is_string
why dont use them. http://www.php.net/manual/en/ref.var.php
You have to put a return
in the function validateType
精彩评论