Copied reproduction code from bugs.php.net to phpt #213

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+51 −0
Split
@@ -0,0 +1,24 @@
+--TEST--
+Bug #54973 SimpleXML casts intergers wrong.
+--SKIPIF--
+<?php
+if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only");
+--FILE--
+<?php
+
+$xml = simplexml_load_string("<xml><number>214748364800</number></xml>");
+echo $xml->number . "\n"; // the proper number
+
+$int = $xml->number / 1024 / 1024 / 1024; // initial cast to an int causes problems
+echo $int . "\n";
+
+$strint = strval($xml->number) / 1024 / 1024 / 1024; // external cast to int behavior
+echo $strint . "\n";
+
+$double = (double) $xml->number / 1024 / 1024 / 1024; // hard cast to a double fixes it
+echo $double . "\n";
+--EXPECT--
+214748364800
+200
+200
+200
@@ -0,0 +1,27 @@
+--TEST--
+Bug #54973 SimpleXML casts intergers wrong.
+--SKIPIF--
+<?php
+if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only");
+--FILE--
+<?php
+
+$xml = simplexml_load_string("<xml><number>922337203685477580800</number></xml>");
+echo $xml->number . "\n"; // the proper number
+
+// initial cast to an int causes problems
+$int = $xml->number / 1024 / 1024 / 1024 / 1024 / 1024 / 1024;
+echo $int . "\n";
+
+// external cast to int behavior
+$strint = strval($xml->number) / 1024 / 1024 / 1024 / 1024 / 1024 / 1024;
+echo $strint . "\n";
+
+// hard cast to a double fixes it
+$double = (double) $xml->number / 1024 / 1024 / 1024 / 1024 / 1024 / 1024;
+echo $double . "\n";
+--EXPECT--
+922337203685477580800
+800
+800
+800