1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-07 06:55:25 +02:00

[ticket/10931] Make to_numeric function globally available.

PHPBB3-10931
This commit is contained in:
Andreas Fischer 2012-06-11 15:22:55 +02:00
parent 09fb9a9efe
commit cbff02db4f
3 changed files with 16 additions and 15 deletions

View File

@ -4987,3 +4987,16 @@ function phpbb_pcre_utf8_support()
} }
return $utf8_pcre_properties; return $utf8_pcre_properties;
} }
/**
* 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.
*/
function phpbb_to_numeric($input)
{
return ($input > PHP_INT_MAX) ? (float) $input : (int) $input;
}

View File

@ -138,7 +138,7 @@ class phpbb_php_ini
if (is_numeric($value)) if (is_numeric($value))
{ {
// Already in bytes. // Already in bytes.
return $this->to_numeric($value); return phpbb_to_numeric($value);
} }
else if (strlen($value) < 2) else if (strlen($value) < 2)
{ {
@ -151,7 +151,7 @@ class phpbb_php_ini
return false; return false;
} }
$value_numeric = $this->to_numeric($value); $value_numeric = phpbb_to_numeric($value);
switch ($value[strlen($value) - 1]) switch ($value[strlen($value) - 1])
{ {
@ -171,17 +171,4 @@ class phpbb_php_ini
return $value_numeric; 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;
}
} }

View File

@ -8,6 +8,7 @@
*/ */
require_once dirname(__FILE__) . '/phpbb_php_ini_fake.php'; require_once dirname(__FILE__) . '/phpbb_php_ini_fake.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case
{ {