From a9ae8299bb3720f7836cd6bc341e850067039437 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Wed, 2 Sep 2026 12:04:47 -0700 Subject: [PATCH 1/3] Reflection: add regression tests for printing boolean constant values Add regression tests for the output of `ReflectionClassConstant::__toString()` and `ReflectionConstant::__toString()` when the value of the constant is boolean `true` or `false`. The `true` cases are already covered by some existing tests, but it seems that the `false` cases are currently untested. --- .../ReflectionClassConstant_toString.phpt | 39 +++++++++++++++++++ .../tests/ReflectionConstant_toString.phpt | 15 +++++++ 2 files changed, 54 insertions(+) create mode 100644 ext/reflection/tests/ReflectionClassConstant_toString.phpt create mode 100644 ext/reflection/tests/ReflectionConstant_toString.phpt diff --git a/ext/reflection/tests/ReflectionClassConstant_toString.phpt b/ext/reflection/tests/ReflectionClassConstant_toString.phpt new file mode 100644 index 000000000000..e3baca55597c --- /dev/null +++ b/ext/reflection/tests/ReflectionClassConstant_toString.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionClassConstant::__toString() and class constant display +--FILE-- + +--EXPECTF-- +Constant [ public bool IS_TRUE ] { 1 } +Constant [ public bool IS_FALSE ] { } +Class [ class Demo ] { + @@ %s %d-%d + + - Constants [2] { + Constant [ public bool IS_TRUE ] { 1 } + Constant [ public bool IS_FALSE ] { } + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [0] { + } +} diff --git a/ext/reflection/tests/ReflectionConstant_toString.phpt b/ext/reflection/tests/ReflectionConstant_toString.phpt new file mode 100644 index 000000000000..74221cc1f13d --- /dev/null +++ b/ext/reflection/tests/ReflectionConstant_toString.phpt @@ -0,0 +1,15 @@ +--TEST-- +ReflectionConstant::__toString() +--FILE-- + +--EXPECT-- +Constant [ bool IS_TRUE ] { 1 } +Constant [ bool IS_FALSE ] { } From 1ed783fa7a135cf1d693e302066da7807c515720 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Wed, 2 Sep 2026 12:07:20 -0700 Subject: [PATCH 2/3] Reflection: print boolean constant values as `true` and `false` Updates the output of `ReflectionClassConstant::__toString()` and `ReflectionConstant::__toString()`, as well as the other ways that class constants are printed, e.g. `ReflectionClass::__toString()`. --- .../delayed_target_validation/has_runtime_errors.phpt | 2 +- ext/reflection/php_reflection.c | 8 ++++++++ ext/reflection/tests/ReflectionClassConstant_basic1.phpt | 4 ++-- .../tests/ReflectionClassConstant_toString.phpt | 8 ++++---- ext/reflection/tests/ReflectionConstant_toString.phpt | 4 ++-- ext/reflection/tests/bug29986.phpt | 2 +- .../gh22681/ReflectionClassConstant_doc_comment.phpt | 4 ++-- ext/reflection/tests/gh22681/ReflectionConstant_name.phpt | 2 +- sapi/cli/tests/006.phpt | 2 +- 9 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Zend/tests/attributes/delayed_target_validation/has_runtime_errors.phpt b/Zend/tests/attributes/delayed_target_validation/has_runtime_errors.phpt index 43ff78e0720d..786b5245837b 100644 --- a/Zend/tests/attributes/delayed_target_validation/has_runtime_errors.phpt +++ b/Zend/tests/attributes/delayed_target_validation/has_runtime_errors.phpt @@ -265,7 +265,7 @@ array(2) { } Error: Attribute "Attribute" cannot target function (allowed targets: class) ******************** -Constant [ bool EXAMPLE ] { 1 } +Constant [ bool EXAMPLE ] { true } array(2) { [0]=> diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 370cfe86f952..8466cbcd27da 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -594,6 +594,10 @@ static void _const_string(smart_str *str, const zend_string *name, const zval *v 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 if (Z_TYPE_P(value) == IS_FALSE) { + smart_str_append(str, ZSTR_KNOWN(ZEND_STR_FALSE)); + } else if (Z_TYPE_P(value) == IS_TRUE) { + smart_str_append(str, ZSTR_KNOWN(ZEND_STR_TRUE)); } else { zend_string *tmp_value_str; zend_string *value_str = zval_get_tmp_string(value, &tmp_value_str); @@ -630,6 +634,10 @@ static void _class_const_string(smart_str *str, const zend_string *name, zend_cl 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 if (Z_TYPE(c->value) == IS_FALSE) { + smart_str_append(str, ZSTR_KNOWN(ZEND_STR_FALSE)); + } else if (Z_TYPE(c->value) == IS_TRUE) { + smart_str_append(str, ZSTR_KNOWN(ZEND_STR_TRUE)); } 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/ReflectionClassConstant_basic1.phpt b/ext/reflection/tests/ReflectionClassConstant_basic1.phpt index 4b8c8a32f785..cfe9bf4d8103 100644 --- a/ext/reflection/tests/ReflectionClassConstant_basic1.phpt +++ b/ext/reflection/tests/ReflectionClassConstant_basic1.phpt @@ -57,8 +57,8 @@ reflectClassConstant($instance, "BAD_CONST"); Reflecting on class constant TestClass::PUB __toString(): -string(57) "/** My Doc comment */ -Constant [ public bool PUB ] { 1 } +string(60) "/** My Doc comment */ +Constant [ public bool PUB ] { true } " getName(): string(3) "PUB" diff --git a/ext/reflection/tests/ReflectionClassConstant_toString.phpt b/ext/reflection/tests/ReflectionClassConstant_toString.phpt index e3baca55597c..83c513e8b42c 100644 --- a/ext/reflection/tests/ReflectionClassConstant_toString.phpt +++ b/ext/reflection/tests/ReflectionClassConstant_toString.phpt @@ -15,14 +15,14 @@ echo new ReflectionClass(Demo::class); ?> --EXPECTF-- -Constant [ public bool IS_TRUE ] { 1 } -Constant [ public bool IS_FALSE ] { } +Constant [ public bool IS_TRUE ] { true } +Constant [ public bool IS_FALSE ] { false } Class [ class Demo ] { @@ %s %d-%d - Constants [2] { - Constant [ public bool IS_TRUE ] { 1 } - Constant [ public bool IS_FALSE ] { } + Constant [ public bool IS_TRUE ] { true } + Constant [ public bool IS_FALSE ] { false } } - Static properties [0] { diff --git a/ext/reflection/tests/ReflectionConstant_toString.phpt b/ext/reflection/tests/ReflectionConstant_toString.phpt index 74221cc1f13d..c60a8252d22b 100644 --- a/ext/reflection/tests/ReflectionConstant_toString.phpt +++ b/ext/reflection/tests/ReflectionConstant_toString.phpt @@ -11,5 +11,5 @@ echo new ReflectionConstant('IS_FALSE'); ?> --EXPECT-- -Constant [ bool IS_TRUE ] { 1 } -Constant [ bool IS_FALSE ] { } +Constant [ bool IS_TRUE ] { true } +Constant [ bool IS_FALSE ] { false } diff --git a/ext/reflection/tests/bug29986.phpt b/ext/reflection/tests/bug29986.phpt index 97aafd3820a0..865c66056761 100644 --- a/ext/reflection/tests/bug29986.phpt +++ b/ext/reflection/tests/bug29986.phpt @@ -20,7 +20,7 @@ Class [ class just_constants ] { @@ %s %d-%d - Constants [5] { - Constant [ public bool BOOLEAN_CONSTANT ] { 1 } + Constant [ public bool BOOLEAN_CONSTANT ] { true } Constant [ public null NULL_CONSTANT ] { } Constant [ public string STRING_CONSTANT ] { This is a string } Constant [ public int INTEGER_CONSTANT ] { 1000 } diff --git a/ext/reflection/tests/gh22681/ReflectionClassConstant_doc_comment.phpt b/ext/reflection/tests/gh22681/ReflectionClassConstant_doc_comment.phpt index 5002f066ff69..2f64d37696bf 100644 --- a/ext/reflection/tests/gh22681/ReflectionClassConstant_doc_comment.phpt +++ b/ext/reflection/tests/gh22681/ReflectionClassConstant_doc_comment.phpt @@ -20,14 +20,14 @@ echo new ReflectionClass(Demo::class); ?> --EXPECTF-- /** F%0oo */ -Constant [ public bool DEMO ] { 1 } +Constant [ public bool DEMO ] { true } string(11) "/** F%0oo */" Class [ class Demo ] { @@ %s(%d) : eval()'d code %d-%d - Constants [1] { /** F%0oo */ - Constant [ public bool DEMO ] { 1 } + Constant [ public bool DEMO ] { true } } - Static properties [0] { diff --git a/ext/reflection/tests/gh22681/ReflectionConstant_name.phpt b/ext/reflection/tests/gh22681/ReflectionConstant_name.phpt index c43397200c82..a9565ba988e6 100644 --- a/ext/reflection/tests/gh22681/ReflectionConstant_name.phpt +++ b/ext/reflection/tests/gh22681/ReflectionConstant_name.phpt @@ -11,5 +11,5 @@ var_dump( $r->getName() ); ?> --EXPECTF-- -Constant [ bool F%0oo ] { 1 } +Constant [ bool F%0oo ] { true } string(4) "F%0oo" diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt index 957543c1a28d..0b7a021a6c4d 100644 --- a/sapi/cli/tests/006.phpt +++ b/sapi/cli/tests/006.phpt @@ -63,7 +63,7 @@ string(%d) "Extension [ extension #%d pcre version %s ] { Constant [ string PCRE_VERSION ] { %s } Constant [ int PCRE_VERSION_MAJOR ] { %d } Constant [ int PCRE_VERSION_MINOR ] { %d } - Constant [ bool PCRE_JIT_SUPPORT ] { %d } + Constant [ bool PCRE_JIT_SUPPORT ] { true } } - Functions { From 98c940c8265bfe79b30cc07059a142b7f98d4b8b Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Wed, 2 Sep 2026 12:10:02 -0700 Subject: [PATCH 3/3] Reflection: add UPGRADING note about changed boolean constant display --- UPGRADING | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UPGRADING b/UPGRADING index 42ee8f4228d4..03f3867bae77 100644 --- a/UPGRADING +++ b/UPGRADING @@ -682,6 +682,13 @@ PHP 8.6 UPGRADE NOTES landed, which is a tautology; an invalid callback throws a TypeError via ZPP before the function body is reached. +- Reflection: + . The outputs of ReflectionClassConstant::__toString() and + ReflectionConstant::__toString() for constants with boolean values have been + changed to use `true` and `false` rather than `1` and an empty string. This + also affects other ways of printing class constants, e.g. + `ReflectionClass::__toString()`. + - Sockets: . socket_addrinfo_lookup() now has an additional optional argument $error_code that, when not null, receives the error code on failure (one of the EAI_*