Skip to content

Commit ab20db9

Browse files
committed
Fix GH-22683: Reflection(Class)Constant::__toString() should not warn on NAN conversions
1 parent 955a2ce commit ab20db9

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ PHP NEWS
8484
dynamic properties shadowing a private parent property). (iliaal)
8585
. Fixed bug GH-22658 (ReflectionConstant::__toString() with a string value
8686
with null bytes truncates output). (DanielEScherzer)
87+
. Fixed bug GH-22683 (Reflection(Class)Constant::__toString() should not warn
88+
on NAN conversions). (Khaled Alam)
8789

8890
- Session:
8991
. Fixed bug GH-21314 (Different session garbage collector behavior between

ext/reflection/php_reflection.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ static void _const_string(smart_str *str, const char *name, zval *value, const c
617617
smart_str_append(str, ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED));
618618
} else if (Z_TYPE_P(value) == IS_STRING) {
619619
smart_str_append(str, Z_STR_P(value));
620+
} else if (Z_TYPE_P(value) == IS_DOUBLE) {
621+
smart_str_append_double(str, Z_DVAL_P(value), (int) EG(precision), false);
620622
} else {
621623
zend_string *tmp_value_str;
622624
zend_string *value_str = zval_get_tmp_string(value, &tmp_value_str);
@@ -649,6 +651,8 @@ static void _class_const_string(smart_str *str, const zend_string *name, zend_cl
649651
smart_str_appends(str, "Array");
650652
} else if (Z_TYPE(c->value) == IS_OBJECT) {
651653
smart_str_appends(str, "Object");
654+
} else if (Z_TYPE(c->value) == IS_DOUBLE) {
655+
smart_str_append_double(str, Z_DVAL(c->value), (int) EG(precision), false);
652656
} else {
653657
zend_string *tmp_value_str;
654658
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)