Skip to content

Commit aaa141a

Browse files
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-22683: Reflection(Class)Constant::__toString() should not warn on NAN conversions (#22694)
2 parents 7cc47ff + c559d6f commit aaa141a

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ PHP NEWS
9090
. Fixed off-by-one in phpdbg_safe_class_lookup() causing class lookups to
9191
always fail during phpdbg's signal-safe interruption path. (jorgsowa)
9292

93+
- Reflection:
94+
. Fixed bug GH-22683 (Reflection(Class)Constant::__toString() should not warn
95+
on NAN conversions). (Khaled Alam)
96+
9397
- Session:
9498
. Fixed bug GH-21314 (Different session garbage collector behavior between
9599
PHP 8.3 and PHP 8.5). (jorgsowa)

ext/reflection/php_reflection.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ static void _const_string(smart_str *str, const char *name, zval *value, const c
609609
smart_str_append(str, ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED));
610610
} else if (Z_TYPE_P(value) == IS_STRING) {
611611
smart_str_append(str, Z_STR_P(value));
612+
} else if (Z_TYPE_P(value) == IS_DOUBLE) {
613+
smart_str_append_double(str, Z_DVAL_P(value), (int) EG(precision), false);
612614
} else {
613615
zend_string *tmp_value_str;
614616
zend_string *value_str = zval_get_tmp_string(value, &tmp_value_str);
@@ -641,6 +643,8 @@ static void _class_const_string(smart_str *str, const zend_string *name, zend_cl
641643
smart_str_appends(str, "Array");
642644
} else if (Z_TYPE(c->value) == IS_OBJECT) {
643645
smart_str_appends(str, "Object");
646+
} else if (Z_TYPE(c->value) == IS_DOUBLE) {
647+
smart_str_append_double(str, Z_DVAL(c->value), (int) EG(precision), false);
644648
} else {
645649
zend_string *tmp_value_str;
646650
zend_string *value_str = zval_get_tmp_string(&c->value, &tmp_value_str);

ext/reflection/tests/gh22683.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-22683 (Reflection(Class)Constant::__toString() should not warn on NAN conversions)
3+
--FILE--
4+
<?php
5+
6+
echo new ReflectionConstant('NAN');
7+
echo new ReflectionConstant('INF');
8+
9+
class Demo {
10+
public const MY_NAN = NAN;
11+
public const MY_INF = INF;
12+
public const MY_FLOAT = 1.5;
13+
public const MY_WHOLE = 2.0;
14+
}
15+
16+
echo new ReflectionClassConstant(Demo::class, 'MY_NAN');
17+
echo new ReflectionClassConstant(Demo::class, 'MY_INF');
18+
echo new ReflectionClassConstant(Demo::class, 'MY_FLOAT');
19+
echo new ReflectionClassConstant(Demo::class, 'MY_WHOLE');
20+
21+
?>
22+
--EXPECT--
23+
Constant [ <persistent> float NAN ] { NAN }
24+
Constant [ <persistent> float INF ] { INF }
25+
Constant [ public float MY_NAN ] { NAN }
26+
Constant [ public float MY_INF ] { INF }
27+
Constant [ public float MY_FLOAT ] { 1.5 }
28+
Constant [ public float MY_WHOLE ] { 2 }

0 commit comments

Comments
 (0)