Skip to content
Browse files

Make serialize precision a configurable option.

  • Loading branch information...
1 parent 7a0efe8 commit b20df54af7e3cbb016379b42be1f22d8b7ddbf9d Ilia Alshanetsky committed May 8, 2003
Showing with 15 additions and 1 deletion.
  1. +2 −0 ext/standard/tests/serialize/bug23298.phpt
  2. +1 −1 ext/standard/var.c
  3. +1 −0 main/main.c
  4. +1 −0 main/php_globals.h
  5. +5 −0 php.ini-dist
  6. +5 −0 php.ini-recommended
View
2 ext/standard/tests/serialize/bug23298.phpt
@@ -1,5 +1,7 @@
--TEST--
Bug #23298 (serialize() and floats/doubles)
+--INI--
+serialize_precision=100
--FILE--
<?php
ini_set('precision', 12);
View
2 ext/standard/var.c
@@ -535,7 +535,7 @@ static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *va
char *s;
ulong slen;
- slen = spprintf(&s, 0, "d:%.100G;", Z_DVAL_PP(struc));
+ slen = spprintf(&s, 0, "d:%.*G;", PG(serialize_precision), Z_DVAL_PP(struc));
smart_str_appendl(buf, s, slen);
efree(s);
return;
View
1 main/main.c
@@ -296,6 +296,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("y2k_compliance", "1", PHP_INI_ALL, OnUpdateBool, y2k_compliance, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("serialize_precision", "100", PHP_INI_ALL, OnUpdateLong, serialize_precision, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
View
1 main/php_globals.h
@@ -69,6 +69,7 @@ struct _php_core_globals {
char *output_handler;
char *unserialize_callback_func;
+ long serialize_precision;
char *safe_mode_exec_dir;
View
5 php.ini-dist
@@ -137,6 +137,11 @@ implicit_flush = Off
; callback-function.
unserialize_callback_func=
+; When floats & doubles are serialized store serialize_precision significant
+; digits after the floating point. The default value ensures that when floats
+; are decoded with unserialize, the data will remain the same.
+serialize_precision = 100
+
; Whether to enable the ability to force arguments to be passed by reference
; at function call time. This method is deprecated and is likely to be
; unsupported in future versions of PHP/Zend. The encouraged method of
View
5 php.ini-recommended
@@ -150,6 +150,11 @@ implicit_flush = Off
; callback-function.
unserialize_callback_func=
+; When floats & doubles are serialized store serialize_precision significant
+; digits after the floating point. The default value ensures that when floats
+; are decoded with unserialize, the data will remain the same.
+serialize_precision = 100
+
; Whether to enable the ability to force arguments to be passed by reference
; at function call time. This method is deprecated and is likely to be
; unsupported in future versions of PHP/Zend. The encouraged method of

0 comments on commit b20df54

Please sign in to comment.
Something went wrong with that request. Please try again.