diff options
author | Andreas Fischer <bantu@phpbb.com> | 2012-06-11 15:15:08 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2012-06-11 15:15:08 +0200 |
commit | 09fb9a9efe048cef102471d1ce79cdeff932776a (patch) | |
tree | e30fa86085e27771a49a1990f3f74d3649e7efb1 /phpBB | |
parent | e9348b172a5b0661b26a8f3a0fe3368568539edb (diff) | |
download | forums-09fb9a9efe048cef102471d1ce79cdeff932776a.tar forums-09fb9a9efe048cef102471d1ce79cdeff932776a.tar.gz forums-09fb9a9efe048cef102471d1ce79cdeff932776a.tar.bz2 forums-09fb9a9efe048cef102471d1ce79cdeff932776a.tar.xz forums-09fb9a9efe048cef102471d1ce79cdeff932776a.zip |
[ticket/10931] Make sure get_bytes() always returns either an int or a float.
PHPBB3-10931
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/php/ini.php | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/phpBB/includes/php/ini.php b/phpBB/includes/php/ini.php index de1cb5096c..bbe592a7df 100644 --- a/phpBB/includes/php/ini.php +++ b/phpBB/includes/php/ini.php @@ -138,7 +138,7 @@ class phpbb_php_ini if (is_numeric($value)) { // Already in bytes. - return $value; + return $this->to_numeric($value); } else if (strlen($value) < 2) { @@ -151,7 +151,7 @@ class phpbb_php_ini return false; } - $value_numeric = (int) $value; + $value_numeric = $this->to_numeric($value); switch ($value[strlen($value) - 1]) { @@ -171,4 +171,17 @@ class phpbb_php_ini return $value_numeric; } + + /** + * Casts a numeric string $input to an appropriate numeric type (i.e. integer or float) + * + * @param string $input A numeric string. + * + * @return int|float Integer $input if $input fits integer, + * float $input otherwise. + */ + protected function to_numeric($input) + { + return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; + } } |