diff --git a/targets/php/php.inc.php b/targets/php/php.inc.php index 96fee31..e2d744e 100644 --- a/targets/php/php.inc.php +++ b/targets/php/php.inc.php @@ -548,13 +548,18 @@ function mtg_php_val_double($val) return 1*$val; } +function mtg_php_check_float($val) +{ + if(is_float($val)) + throw new Exception("Incompatible type, expected uint64, float given: $val"); +} + function mtg_php_val_uint64($val) { if(!is_numeric($val)) throw new Exception("Bad item, not a number(" . serialize($val) . ")"); $val = 1*$val; - if(is_float($val)) - throw new Exception("Value not in range: $val"); + mtg_php_check_float($val); return $val; } @@ -563,8 +568,7 @@ function mtg_php_val_int64($val) if(!is_numeric($val)) throw new Exception("Bad item, not a number(" . serialize($val) . ")"); $val = 1*$val; - if(is_float($val)) - throw new Exception("Value not in range: $val"); + mtg_php_check_float($val); return $val; } @@ -573,7 +577,8 @@ function mtg_php_val_uint32($val) if(!is_numeric($val)) throw new Exception("Bad item, not a number(" . serialize($val) . ")"); $val = 1*$val; - if(($val < 0 && $val < -2147483648) || ($val > 0 && $val > 0xFFFFFFFF) || is_float($val)) + mtg_php_check_float($val); + if(($val < 0 && $val < -2147483648) || ($val > 0 && $val > 0xFFFFFFFF)) throw new Exception("Value not in range: $val"); return $val; } @@ -583,7 +588,8 @@ function mtg_php_val_int32($val) if(!is_numeric($val)) throw new Exception("Bad item, not a number(" . serialize($val) . ")"); $val = 1*$val; - if($val > 2147483647 || $val < -2147483648 || is_float($val)) + mtg_php_check_float($val); + if($val > 2147483647 || $val < -2147483648) throw new Exception("Value not in range: $val"); return $val; } @@ -593,7 +599,8 @@ function mtg_php_val_uint16($val) if(!is_numeric($val)) throw new Exception("Bad item, not a number(" . serialize($val) . ")"); $val = 1*$val; - if($val > 0xFFFF || $val < 0 || is_float($val)) + mtg_php_check_float($val); + if($val > 0xFFFF || $val < 0) throw new Exception("Value not in range: $val"); return $val; } @@ -603,7 +610,8 @@ function mtg_php_val_int16($val) if(!is_numeric($val)) throw new Exception("Bad item, not a number(" . serialize($val) . ")"); $val = 1*$val; - if($val > 32767 || $val < -32768 || is_float($val)) + mtg_php_check_float($val); + if($val > 32767 || $val < -32768) throw new Exception("Value not in range: $val"); return $val; } @@ -613,7 +621,8 @@ function mtg_php_val_uint8($val) if(!is_numeric($val)) throw new Exception("Bad item, not a number(" . serialize($val) . ")"); $val = 1*$val; - if($val > 0xFF || $val < 0 || is_float($val)) + mtg_php_check_float($val); + if($val > 0xFF || $val < 0) throw new Exception("Value not in range: $val"); return $val; } @@ -623,7 +632,8 @@ function mtg_php_val_int8($val) if(!is_numeric($val)) throw new Exception("Bad item, not a number(" . serialize($val) . ")"); $val = 1*$val; - if($val > 127 || $val < -128 || is_float($val)) + mtg_php_check_float($val); + if($val > 127 || $val < -128) throw new Exception("Value not in range: $val"); return $val; }