I have a problem with typecast methods.
Here is a setter of an object:
function setKind($kind)
{
if (is_int((int)$k ind) and (strlen($kind)< =6)) {
$this->kind = $kind;
return true;
}
else {
return false;
}
}
My goal is, not to allow to set float or string values or too big
integer values (max. 6 digits!) for an object property.
I need to check, if the $kind is an int, but the function argument $kind
is an string from the database or an input field.
I don't know how to convert and decline illegal aruments.
If the typecast fails in my upper sample, the function returns TRUE
though. That is not correct! It has to return FALSE.
I thought about is_numeric, but that would accept float values as well
and are not allowed to set (ONLY int).
does any body know how to handle that problem?
thanx in advance,
Lars
Here is a setter of an object:
function setKind($kind)
{
if (is_int((int)$k ind) and (strlen($kind)< =6)) {
$this->kind = $kind;
return true;
}
else {
return false;
}
}
My goal is, not to allow to set float or string values or too big
integer values (max. 6 digits!) for an object property.
I need to check, if the $kind is an int, but the function argument $kind
is an string from the database or an input field.
I don't know how to convert and decline illegal aruments.
If the typecast fails in my upper sample, the function returns TRUE
though. That is not correct! It has to return FALSE.
I thought about is_numeric, but that would accept float values as well
and are not allowed to set (ONLY int).
does any body know how to handle that problem?
thanx in advance,
Lars
Comment