diff --git a/src/ActiveResource/Formats/XML.php b/src/ActiveResource/Formats/XML.php index c714e29..e3c9876 100644 --- a/src/ActiveResource/Formats/XML.php +++ b/src/ActiveResource/Formats/XML.php @@ -64,11 +64,10 @@ private function arrayToNode(array $array, $array_node = false) $xml_name = $this->endash($xml_name); // Big numbers detect stub for x32 architecture - // Restriction: float numbers greater than PHP_INT_MAX and without digits - // after point will be encoded as integer - if (is_float($value) && $value > PHP_INT_MAX && preg_match("/^\d+$/", $value)) + // Restriction: all numbers greater or equal PHP_INT_MAX will be encoded as integer + if (is_float($value) && $value >= PHP_INT_MAX) { - $node = sprintf('<%s type="integer">%s', + $node = sprintf('<%s type="integer">%0.0f', $xml_name, $value, $xml_name ); } @@ -139,7 +138,7 @@ private function nodeToArray(\SimpleXMLElement $element, $is_array = false) switch ($node['type']) { case 'integer': - $data[$name] = floatval($node) > PHP_INT_MAX ? floatval($node) : intval($node); + $data[$name] = floatval($node) >= PHP_INT_MAX ? floatval($node) : intval($node); break; case 'boolean': $data[$name] = false !== stripos($node, 'true'); diff --git a/tests/ActiveResource/Formats/XMLTest.php b/tests/ActiveResource/Formats/XMLTest.php index aacdb83..bc8555a 100644 --- a/tests/ActiveResource/Formats/XMLTest.php +++ b/tests/ActiveResource/Formats/XMLTest.php @@ -98,6 +98,9 @@ public function testThreeLevelsWithArray() public function recordsXmlAndArrayDataProvider() { + $big_number = PHP_INT_MAX; + $big_number2 = PHP_INT_MAX * 2; + return array( array( ' @@ -113,8 +116,8 @@ public function recordsXmlAndArrayDataProvider() 1.5 135 - ' . PHP_INT_MAX . ' - ' . (PHP_INT_MAX + 1) . ' + ' . $big_number . ' + ' . sprintf("%0.0f", $big_number2) . ' yes ' @@ -131,8 +134,8 @@ public function recordsXmlAndArrayDataProvider() 'parent_id' => null, 'ad_revenue' => 1.50, 'optimum_viewing_angle' => 135.0, - 'dream_account' => floatval(PHP_INT_MAX), - 'debt_per_life' => floatval(PHP_INT_MAX + 1), + 'dream_account' => $big_number, + 'debt_per_life' => $big_number2, 'resident' => 'yes' ) ),