summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Faulds <ajf@ajf.me>2015-12-18 19:29:35 +0000
committerAndrea Faulds <ajf@ajf.me>2015-12-18 19:31:21 +0000
commit8d217db369d83de22db6c2e6ad9a440d6c59518f (patch)
treeb9b248cf9d2c808aea118b0cd3e028e7e731bf76
parent8f9af36da35eef78728a46890ba5f1f114d7a0b0 (diff)
downloadphp-git-8d217db369d83de22db6c2e6ad9a440d6c59518f.tar.gz
Fix bug #66179
This also fixes ext/standard/tests/general_functions/var_export-locale.phpt to actually run the floating-point section.
-rw-r--r--NEWS1
-rw-r--r--ext/standard/tests/general_functions/var_export-locale.phpt138
-rw-r--r--ext/standard/tests/general_functions/var_export_basic1.phpt4
-rw-r--r--ext/standard/tests/general_functions/var_export_basic3.phpt96
-rw-r--r--ext/standard/tests/general_functions/var_export_bug66179.phpt29
-rw-r--r--ext/standard/var.c7
-rw-r--r--tests/lang/bug24640.phpt4
7 files changed, 200 insertions, 79 deletions
diff --git a/NEWS b/NEWS
index 131777052d..baca4f29e3 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,7 @@ PHP NEWS
. Fixed bug #71154 (Incorrect HT iterator invalidation causes iterator reuse).
(Nikita)
. Fixed bug #52355 (Negating zero does not produce negative zero). (Andrea)
+ . Fixed bug #66179 (var_export() exports float as integer). (Andrea)
. CURL:
. Fixed bug #71144 (Sementation fault when using cURL with ZTS).
diff --git a/ext/standard/tests/general_functions/var_export-locale.phpt b/ext/standard/tests/general_functions/var_export-locale.phpt
index 1cadb4aa55..47dfcbb3ee 100644
--- a/ext/standard/tests/general_functions/var_export-locale.phpt
+++ b/ext/standard/tests/general_functions/var_export-locale.phpt
@@ -30,12 +30,12 @@ $valid_ints = array(
'0x12ab',
'0Xfff',
'0XFA',
- -0x80000000, // max negative integer as hexadecimal
+ -0x7fffffff - 1, // max negative integer as hexadecimal
'0x7fffffff', // max positive integer as hexadecimal
0x7FFFFFFF, // max positive integer as hexadecimal
'0123', // integer as octal
01, // should be quivalent to octal 1
- -020000000000, // max negative integer as octal
+ -017777777777 - 1, // max negative integer as octal
017777777777, // max positive integer as octal
);
$counter = 1;
@@ -79,12 +79,12 @@ $counter++;
echo "*** Testing var_export() with valid float values ***\n";
// different valid float vlaues
$valid_floats = array(
- -2147483649, // float value
- 2147483648, // float value
- -0x80000001, // float value, beyond max negative int
- 0x800000001, // float value, beyond max positive int
- 020000000001, // float value, beyond max positive int
- -020000000001, // float value, beyond max negative int
+ (float)-2147483649, // float value
+ (float)2147483648, // float value
+ (float)-0x80000001, // float value, beyond max negative int
+ (float)0x800000001, // float value, beyond max positive int
+ (float)020000000001, // float value, beyond max positive int
+ (float)-020000000001, // float value, beyond max negative int
0.0,
-0.1,
10.0000000000000000005,
@@ -103,7 +103,7 @@ $valid_floats = array(
$counter = 1;
/* Loop to check for above float values with var_export() */
echo "\n*** Output for float values ***\n";
-foreach($valid_bool as $float_value) {
+foreach($valid_floats as $float_value) {
echo "\nIteration ".$counter."\n";
var_export( $float_value );
echo "\n";
@@ -467,39 +467,123 @@ string(5) "false"
*** Output for float values ***
Iteration 1
-1
-1
-string(1) "1"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
Iteration 2
-true
-true
-string(4) "true"
+2147483648.0
+2147483648.0
+string(12) "2147483648.0"
Iteration 3
-true
-true
-string(4) "true"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
Iteration 4
-0
-0
-string(1) "0"
+34359738369.0
+34359738369.0
+string(13) "34359738369.0"
Iteration 5
-false
-false
-string(5) "false"
+2147483649.0
+2147483649.0
+string(12) "2147483649.0"
Iteration 6
-false
-false
-string(5) "false"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
+
+
+Iteration 7
+0.0
+0.0
+string(3) "0.0"
+
+
+Iteration 8
+-0.10000000000000001
+-0.10000000000000001
+string(20) "-0.10000000000000001"
+
+
+Iteration 9
+10.0
+10.0
+string(4) "10.0"
+
+
+Iteration 10
+1050000.0
+1050000.0
+string(9) "1050000.0"
+
+
+Iteration 11
+100000.0
+100000.0
+string(8) "100000.0"
+
+
+Iteration 12
+1.0000000000000001E-5
+1.0000000000000001E-5
+string(21) "1.0000000000000001E-5"
+
+
+Iteration 13
+100000.0
+100000.0
+string(8) "100000.0"
+
+
+Iteration 14
+100000.0
+100000.0
+string(8) "100000.0"
+
+
+Iteration 15
+100000.0
+100000.0
+string(8) "100000.0"
+
+
+Iteration 16
+1.0000000000000001E-5
+1.0000000000000001E-5
+string(21) "1.0000000000000001E-5"
+
+
+Iteration 17
+5000000.0
+5000000.0
+string(9) "5000000.0"
+
+
+Iteration 18
+6.0000000000000006E-20
+6.0000000000000006E-20
+string(22) "6.0000000000000006E-20"
+
+
+Iteration 19
+5.0000000000000001E+42
+5.0000000000000001E+42
+string(22) "5.0000000000000001E+42"
+
+
+Iteration 20
+3.4000000000000001E-33
+3.4000000000000001E-33
+string(22) "3.4000000000000001E-33"
*** Testing var_export() with valid strings ***
diff --git a/ext/standard/tests/general_functions/var_export_basic1.phpt b/ext/standard/tests/general_functions/var_export_basic1.phpt
index cba04b8507..5f7b89124c 100644
--- a/ext/standard/tests/general_functions/var_export_basic1.phpt
+++ b/ext/standard/tests/general_functions/var_export_basic1.phpt
@@ -22,12 +22,12 @@ $valid_ints = array(
"'0x12ab'" => '0x12ab',
"'0Xfff'" => '0Xfff',
"'0XFA'" => '0XFA',
- "-0x80000000" => -0x80000000, // max negative integer as hexadecimal
+ "-0x80000000" => -0x7FFFFFFF - 1, // max negative integer as hexadecimal
"'0x7fffffff'" => '0x7fffffff', // max positive integer as hexadecimal
"0x7FFFFFFF" => 0x7FFFFFFF, // max positive integer as hexadecimal
"'0123'" => '0123', // integer as octal
"01912" => 01, // should be quivalent to octal 1
- "-020000000000" => -020000000000, // max negative integer as octal
+ "-020000000000" => -017777777777 - 1, // max negative integer as octal
"017777777777" => 017777777777, // max positive integer as octal
);
diff --git a/ext/standard/tests/general_functions/var_export_basic3.phpt b/ext/standard/tests/general_functions/var_export_basic3.phpt
index 58c0448167..35692ad627 100644
--- a/ext/standard/tests/general_functions/var_export_basic3.phpt
+++ b/ext/standard/tests/general_functions/var_export_basic3.phpt
@@ -13,12 +13,12 @@ serialize_precision=17
echo "*** Testing var_export() with valid float values ***\n";
// different valid float vlaues
$valid_floats = array(
- "-2147483649" => -2147483649, // float value
- "2147483648" => 2147483648, // float value
- "-0x80000001" => -0x80000001, // float value, beyond max negative int
- "0x800000001" => 0x800000001, // float value, beyond max positive int
- "020000000001" => 020000000001, // float value, beyond max positive int
- "-020000000001" => -020000000001, // float value, beyond max negative int
+ "-2147483649" => (float)-2147483649, // float value
+ "2147483648" => (float)2147483648, // float value
+ "-0x80000001" => (float)-0x80000001, // float value, beyond max negative int
+ "0x800000001" => (float)0x800000001, // float value, beyond max positive int
+ "020000000001" => (float)020000000001, // float value, beyond max positive int
+ "-020000000001" => (float)-020000000001, // float value, beyond max negative int
"0.0" => 0.0,
"-0.1" => -0.1,
"10.0000000000000000005" => 10.0000000000000000005,
@@ -54,45 +54,45 @@ foreach($valid_floats as $key => $float_value) {
*** Output for float values ***
-- Iteration: -2147483649 --
--2147483649
--2147483649
-string(11) "-2147483649"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
-- Iteration: 2147483648 --
-2147483648
-2147483648
-string(10) "2147483648"
+2147483648.0
+2147483648.0
+string(12) "2147483648.0"
-- Iteration: -0x80000001 --
--2147483649
--2147483649
-string(11) "-2147483649"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
-- Iteration: 0x800000001 --
-34359738369
-34359738369
-string(11) "34359738369"
+34359738369.0
+34359738369.0
+string(13) "34359738369.0"
-- Iteration: 020000000001 --
-2147483649
-2147483649
-string(10) "2147483649"
+2147483649.0
+2147483649.0
+string(12) "2147483649.0"
-- Iteration: -020000000001 --
--2147483649
--2147483649
-string(11) "-2147483649"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
-- Iteration: 0.0 --
-0
-0
-string(1) "0"
+0.0
+0.0
+string(3) "0.0"
-- Iteration: -0.1 --
@@ -102,21 +102,21 @@ string(20) "-0.10000000000000001"
-- Iteration: 10.0000000000000000005 --
-10
-10
-string(2) "10"
+10.0
+10.0
+string(4) "10.0"
-- Iteration: 10.5e+5 --
-1050000
-1050000
-string(7) "1050000"
+1050000.0
+1050000.0
+string(9) "1050000.0"
-- Iteration: 1e5 --
-100000
-100000
-string(6) "100000"
+100000.0
+100000.0
+string(8) "100000.0"
-- Iteration: 1e-5 --
@@ -126,21 +126,21 @@ string(21) "1.0000000000000001E-5"
-- Iteration: 1e+5 --
-100000
-100000
-string(6) "100000"
+100000.0
+100000.0
+string(8) "100000.0"
-- Iteration: 1E5 --
-100000
-100000
-string(6) "100000"
+100000.0
+100000.0
+string(8) "100000.0"
-- Iteration: 1E+5 --
-100000
-100000
-string(6) "100000"
+100000.0
+100000.0
+string(8) "100000.0"
-- Iteration: 1E-5 --
@@ -150,9 +150,9 @@ string(21) "1.0000000000000001E-5"
-- Iteration: .5e+7 --
-5000000
-5000000
-string(7) "5000000"
+5000000.0
+5000000.0
+string(9) "5000000.0"
-- Iteration: .6e-19 --
diff --git a/ext/standard/tests/general_functions/var_export_bug66179.phpt b/ext/standard/tests/general_functions/var_export_bug66179.phpt
new file mode 100644
index 0000000000..15952199e5
--- /dev/null
+++ b/ext/standard/tests/general_functions/var_export_bug66179.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Bug #66179 (var_export() exports float as integer)
+--FILE--
+<?php
+
+var_export(1.0);
+echo PHP_EOL;
+var_export(123.0);
+echo PHP_EOL;
+var_export(-1.0);
+echo PHP_EOL;
+var_export(-123.0);
+echo PHP_EOL;
+var_export(0.0);
+echo PHP_EOL;
+var_export(-0.0);
+echo PHP_EOL;
+var_export(10000000000000000.0);
+echo PHP_EOL;
+
+?>
+--EXPECTF--
+1.0
+123.0
+-1.0
+-123.0
+0.0
+-0.0
+10000000000000000.0
diff --git a/ext/standard/var.c b/ext/standard/var.c
index 7ae9fcf105..881ac5a2fe 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -460,6 +460,13 @@ again:
case IS_DOUBLE:
tmp_len = spprintf(&tmp_str, 0,"%.*H", PG(serialize_precision), Z_DVAL_P(struc));
smart_str_appendl(buf, tmp_str, tmp_len);
+ /* Without a decimal point, PHP treats a number literal as an int.
+ * This check even works for scientific notation, because the
+ * mantissa always contains a decimal point.
+ */
+ if (NULL == strchr(tmp_str, '.')) {
+ smart_str_appendl(buf, ".0", 2);
+ }
efree(tmp_str);
break;
case IS_STRING:
diff --git a/tests/lang/bug24640.phpt b/tests/lang/bug24640.phpt
index d02889101e..ac3d78d06c 100644
--- a/tests/lang/bug24640.phpt
+++ b/tests/lang/bug24640.phpt
@@ -112,7 +112,7 @@ float(I%s)
I%s
I%s
------
-0
+0.0
float(0)
0
0
@@ -122,7 +122,7 @@ float(I%s)
I%s
I%s
------
-0
+0.0
float(0)
0
0