From 501d10ec9a6b31bc7c14a3a4a3fad269ca5b63d7 Mon Sep 17 00:00:00 2001 From: Khaled Alam Date: Sat, 11 Jul 2026 14:46:53 +0400 Subject: [PATCH 1/2] Fix GH-22683: Reflection(Class)Constant::__toString() should not warn on NAN conversions --- NEWS | 4 ++++ ext/reflection/php_reflection.c | 10 +++++++++ ext/reflection/tests/gh22683.phpt | 34 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 ext/reflection/tests/gh22683.phpt diff --git a/NEWS b/NEWS index f40c6dfd8da6..9599aa0f8a8d 100644 --- a/NEWS +++ b/NEWS @@ -71,6 +71,10 @@ PHP NEWS . Fixed off-by-one in phpdbg_safe_class_lookup() causing class lookups to always fail during phpdbg's signal-safe interruption path. (jorgsowa) +- Reflection: + . Fixed bug GH-22683 (Reflection(Class)Constant::__toString() should not warn + on NAN conversions). (Khaled Alam) + - Session: . Fixed bug GH-21314 (Different session garbage collector behavior between PHP 8.3 and PHP 8.5). (jorgsowa) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f04bd020b770..205b46106b83 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -609,6 +609,11 @@ static void _const_string(smart_str *str, const char *name, zval *value, const c smart_str_append(str, ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED)); } else if (Z_TYPE_P(value) == IS_STRING) { smart_str_append(str, Z_STR_P(value)); + } else if (Z_TYPE_P(value) == IS_DOUBLE) { + /* Format the double directly to avoid a spurious "unexpected NAN value + * was coerced to string" warning: the conversion is done by reflection + * itself, not by user code performing a string coercion. */ + smart_str_append_double(str, Z_DVAL_P(value), (int) EG(precision), false); } else { zend_string *tmp_value_str; zend_string *value_str = zval_get_tmp_string(value, &tmp_value_str); @@ -641,6 +646,11 @@ static void _class_const_string(smart_str *str, const zend_string *name, zend_cl smart_str_appends(str, "Array"); } else if (Z_TYPE(c->value) == IS_OBJECT) { smart_str_appends(str, "Object"); + } else if (Z_TYPE(c->value) == IS_DOUBLE) { + /* Format the double directly to avoid a spurious "unexpected NAN value + * was coerced to string" warning: the conversion is done by reflection + * itself, not by user code performing a string coercion. */ + smart_str_append_double(str, Z_DVAL(c->value), (int) EG(precision), false); } else { zend_string *tmp_value_str; zend_string *value_str = zval_get_tmp_string(&c->value, &tmp_value_str); diff --git a/ext/reflection/tests/gh22683.phpt b/ext/reflection/tests/gh22683.phpt new file mode 100644 index 000000000000..bb6b075ac9be --- /dev/null +++ b/ext/reflection/tests/gh22683.phpt @@ -0,0 +1,34 @@ +--TEST-- +GH-22683 (Reflection(Class)Constant::__toString() should not warn on NAN conversions) +--FILE-- + +--EXPECT-- +Constant [ float NAN ] { NAN } +Constant [ float INF ] { INF } +Constant [ public float MY_NAN ] { NAN } +Constant [ public float MY_INF ] { INF } +Constant [ public float MY_FLOAT ] { 1.5 } +Constant [ public float MY_WHOLE ] { 2 } From baf8c77d946b33a649e1f6a76c32ce4a58690943 Mon Sep 17 00:00:00 2001 From: Khaled Alam Date: Sat, 11 Jul 2026 14:49:50 +0400 Subject: [PATCH 2/2] doc: remove unnecessary comments. --- ext/reflection/php_reflection.c | 6 ------ ext/reflection/tests/gh22683.phpt | 1 - 2 files changed, 7 deletions(-) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 205b46106b83..13df0b2bbb4d 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -610,9 +610,6 @@ static void _const_string(smart_str *str, const char *name, zval *value, const c } else if (Z_TYPE_P(value) == IS_STRING) { smart_str_append(str, Z_STR_P(value)); } else if (Z_TYPE_P(value) == IS_DOUBLE) { - /* Format the double directly to avoid a spurious "unexpected NAN value - * was coerced to string" warning: the conversion is done by reflection - * itself, not by user code performing a string coercion. */ smart_str_append_double(str, Z_DVAL_P(value), (int) EG(precision), false); } else { zend_string *tmp_value_str; @@ -647,9 +644,6 @@ static void _class_const_string(smart_str *str, const zend_string *name, zend_cl } else if (Z_TYPE(c->value) == IS_OBJECT) { smart_str_appends(str, "Object"); } else if (Z_TYPE(c->value) == IS_DOUBLE) { - /* Format the double directly to avoid a spurious "unexpected NAN value - * was coerced to string" warning: the conversion is done by reflection - * itself, not by user code performing a string coercion. */ smart_str_append_double(str, Z_DVAL(c->value), (int) EG(precision), false); } else { zend_string *tmp_value_str; diff --git a/ext/reflection/tests/gh22683.phpt b/ext/reflection/tests/gh22683.phpt index bb6b075ac9be..9280a3f4a685 100644 --- a/ext/reflection/tests/gh22683.phpt +++ b/ext/reflection/tests/gh22683.phpt @@ -3,7 +3,6 @@ GH-22683 (Reflection(Class)Constant::__toString() should not warn on NAN convers --FILE--