From 087f38f3476b2f6c73cf2567ccbe19636c2c975d Mon Sep 17 00:00:00 2001 From: Oleg Efimov Date: Thu, 29 May 2025 21:46:11 +0100 Subject: [PATCH] Fix GH-18695: float numbers zero fraction is now preserved in zend_ast_export() (#18699) --- NEWS | 4 ++++ Zend/tests/ast/ast_serialize_floats.phpt | 26 ++++++++++++++++++++++++ Zend/zend_ast.c | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/ast/ast_serialize_floats.phpt diff --git a/NEWS b/NEWS index 466ba5d8965..379718ba2a9 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.3.23 +- Core: + . Fixed GH-18695 (zend_ast_export() - float number is not preserved). + (Oleg Efimov) + - Date: . Fix leaks with multiple calls to DatePeriod iterator current(). (nielsdos) diff --git a/Zend/tests/ast/ast_serialize_floats.phpt b/Zend/tests/ast/ast_serialize_floats.phpt new file mode 100644 index 00000000000..164b8b03338 --- /dev/null +++ b/Zend/tests/ast/ast_serialize_floats.phpt @@ -0,0 +1,26 @@ +--TEST-- +Serialization of floats are correct +--INI-- +zend.assertions=1 +--FILE-- +getMessage(), ' failed', PHP_EOL; +} +try { + assert(!is_float(1.1)); +} catch (AssertionError $e) { + echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL; +} +try { + assert(!is_float(1234.5678)); +} catch (AssertionError $e) { + echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL; +} +?> +--EXPECT-- +assert(): assert(!is_float(0.0)) failed +assert(): assert(!is_float(1.1)) failed +assert(): assert(!is_float(1234.5678)) failed diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 0fb50e2eae1..f8c4ca17a9b 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1563,7 +1563,7 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priorit break; case IS_DOUBLE: smart_str_append_double( - str, Z_DVAL_P(zv), (int) EG(precision), /* zero_fraction */ false); + str, Z_DVAL_P(zv), (int) EG(precision), /* zero_fraction */ true); break; case IS_STRING: smart_str_appendc(str, '\'');