Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ 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) {
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);
Expand Down Expand Up @@ -641,6 +643,8 @@ 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) {
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);
Expand Down
33 changes: 33 additions & 0 deletions ext/reflection/tests/gh22683.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
GH-22683 (Reflection(Class)Constant::__toString() should not warn on NAN conversions)
--FILE--
<?php

set_error_handler(function ($errno, $errstr) {
echo "Unexpected warning: $errstr\n";
return true;
});

echo new ReflectionConstant('NAN');
echo new ReflectionConstant('INF');

class Demo {
public const MY_NAN = NAN;
public const MY_INF = INF;
public const MY_FLOAT = 1.5;
public const MY_WHOLE = 2.0;
}

echo new ReflectionClassConstant(Demo::class, 'MY_NAN');
echo new ReflectionClassConstant(Demo::class, 'MY_INF');
echo new ReflectionClassConstant(Demo::class, 'MY_FLOAT');
echo new ReflectionClassConstant(Demo::class, 'MY_WHOLE');

?>
--EXPECT--
Constant [ <persistent> float NAN ] { NAN }
Constant [ <persistent> 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 }
Loading