Browse Source

Fix bug #66179

This also fixes ext/standard/tests/general_functions/var_export-locale.phpt
to actually run the floating-point section.
pull/1713/head
Andrea Faulds 11 years ago
parent
commit
8d217db369
  1. 1
      NEWS
  2. 138
      ext/standard/tests/general_functions/var_export-locale.phpt
  3. 4
      ext/standard/tests/general_functions/var_export_basic1.phpt
  4. 96
      ext/standard/tests/general_functions/var_export_basic3.phpt
  5. 29
      ext/standard/tests/general_functions/var_export_bug66179.phpt
  6. 7
      ext/standard/var.c
  7. 4
      tests/lang/bug24640.phpt

1
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).

138
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 ***

4
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
);

96
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 --

29
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

7
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:

4
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

Loading…
Cancel
Save