Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1b8414

Browse files
committed
bug #18216 [Intl] Fix invalid numeric literal on PHP 7 (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- [Intl] Fix invalid numeric literal on PHP 7 | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Work around `true === is_float(-9223372036854775808)`. Commits ------- 999c0a5 [NumberFormatter] Fix invalid numeric literal on PHP 7
2 parents d220830 + 999c0a5 commit d1b8414

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,18 @@ class NumberFormatter
213213
);
214214

215215
/**
216-
* The maximum values of the integer type in 32 bit platforms.
216+
* The maximum value of the integer type in 32 bit platforms.
217217
*
218-
* @var array
218+
* @var int
219219
*/
220-
private static $int32Range = array(
221-
'positive' => 2147483647,
222-
'negative' => -2147483648,
223-
);
220+
private static $int32Max = 2147483647;
224221

225222
/**
226-
* The maximum values of the integer type in 64 bit platforms.
223+
* The maximum value of the integer type in 64 bit platforms.
227224
*
228-
* @var array
225+
* @var int|float
229226
*/
230-
private static $int64Range = array(
231-
'positive' => 9223372036854775807,
232-
'negative' => -9223372036854775808,
233-
);
227+
private static $int64Max = 9223372036854775807;
234228

235229
private static $enSymbols = array(
236230
self::DECIMAL => array('.', ',', ';', '%', '0', '#', '-', '+', '¤', '¤¤', '.', 'E', '', '*', '', 'NaN', '@', ','),
@@ -508,7 +502,7 @@ public function parseCurrency($value, &$currency, &$position = null)
508502
* @param int $type Type of the formatting, one of the format type constants. NumberFormatter::TYPE_DOUBLE by default
509503
* @param int $position Offset to begin the parsing on return this value will hold the offset at which the parsing ended
510504
*
511-
* @return bool|string The parsed value of false on error
505+
* @return int|float|false The parsed value of false on error
512506
*
513507
* @see http://www.php.net/manual/en/numberformatter.parse.php
514508
*/
@@ -795,7 +789,7 @@ private function convertValueDataType($value, $type)
795789
*/
796790
private function getInt32Value($value)
797791
{
798-
if ($value > self::$int32Range['positive'] || $value < self::$int32Range['negative']) {
792+
if ($value > self::$int32Max || $value < -self::$int32Max - 1) {
799793
return false;
800794
}
801795

@@ -808,20 +802,18 @@ private function getInt32Value($value)
808802
* @param mixed $value The value to be converted
809803
*
810804
* @return int|float|false The converted value
811-
*
812-
* @see https://bugs.php.net/bug.php?id=59597 Bug #59597
813805
*/
814806
private function getInt64Value($value)
815807
{
816-
if ($value > self::$int64Range['positive'] || $value < self::$int64Range['negative']) {
808+
if ($value > self::$int64Max || $value < -self::$int64Max - 1) {
817809
return false;
818810
}
819811

820-
if (PHP_INT_SIZE !== 8 && ($value > self::$int32Range['positive'] || $value <= self::$int32Range['negative'])) {
812+
if (PHP_INT_SIZE !== 8 && ($value > self::$int32Max || $value <= -self::$int32Max - 1)) {
821813
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
822814
// The negative PHP_INT_MAX was being converted to float
823815
if (
824-
$value == self::$int32Range['negative'] &&
816+
$value == -self::$int32Max - 1 &&
825817
((PHP_VERSION_ID < 50400 && PHP_VERSION_ID >= 50314) || PHP_VERSION_ID >= 50404 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone')))
826818
) {
827819
return (int) $value;
@@ -834,7 +826,7 @@ private function getInt64Value($value)
834826
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
835827
// A 32 bit integer was being generated instead of a 64 bit integer
836828
if (
837-
($value > self::$int32Range['positive'] || $value < self::$int32Range['negative']) &&
829+
($value > self::$int32Max || $value < -self::$int32Max - 1) &&
838830
(PHP_VERSION_ID < 50314 || (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50404)) &&
839831
!(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))
840832
) {

0 commit comments

Comments
 (0)