Commit 0da9d196b16 for php.net
commit 0da9d196b1621aa9549f4e98c556ffa0ee50727e
Author: Daniel Scherzer <daniel.e.scherzer@gmail.com>
Date: Wed Sep 2 12:07:20 2026 -0700
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()`.
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 43ff78e0720..786b5245837 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 @@ function demoFn() {
}
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 370cfe86f95..8466cbcd27d 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 4b8c8a32f78..cfe9bf4d810 100644
--- a/ext/reflection/tests/ReflectionClassConstant_basic1.phpt
+++ b/ext/reflection/tests/ReflectionClassConstant_basic1.phpt
@@ -57,8 +57,8 @@ class TestClass {
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 e3baca55597..83c513e8b42 100644
--- a/ext/reflection/tests/ReflectionClassConstant_toString.phpt
+++ b/ext/reflection/tests/ReflectionClassConstant_toString.phpt
@@ -15,14 +15,14 @@ class Demo {
?>
--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 [ <user> 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 74221cc1f13..c60a8252d22 100644
--- a/ext/reflection/tests/ReflectionConstant_toString.phpt
+++ b/ext/reflection/tests/ReflectionConstant_toString.phpt
@@ -11,5 +11,5 @@
?>
--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 97aafd3820a..865c6605676 100644
--- a/ext/reflection/tests/bug29986.phpt
+++ b/ext/reflection/tests/bug29986.phpt
@@ -20,7 +20,7 @@ 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 5002f066ff6..2f64d37696b 100644
--- a/ext/reflection/tests/gh22681/ReflectionClassConstant_doc_comment.phpt
+++ b/ext/reflection/tests/gh22681/ReflectionClassConstant_doc_comment.phpt
@@ -20,14 +20,14 @@ class Demo {
?>
--EXPECTF--
/** F%0oo */
-Constant [ public bool DEMO ] { 1 }
+Constant [ public bool DEMO ] { true }
string(11) "/** F%0oo */"
Class [ <user> 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 c43397200c8..a9565ba988e 100644
--- a/ext/reflection/tests/gh22681/ReflectionConstant_name.phpt
+++ b/ext/reflection/tests/gh22681/ReflectionConstant_name.phpt
@@ -11,5 +11,5 @@
?>
--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 957543c1a28..af9c8f8eb81 100644
--- a/sapi/cli/tests/006.phpt
+++ b/sapi/cli/tests/006.phpt
@@ -63,7 +63,7 @@
Constant [ <persistent> string PCRE_VERSION ] { %s }
Constant [ <persistent> int PCRE_VERSION_MAJOR ] { %d }
Constant [ <persistent> int PCRE_VERSION_MINOR ] { %d }
- Constant [ <persistent> bool PCRE_JIT_SUPPORT ] { %d }
+ Constant [ <persistent> bool PCRE_JIT_SUPPORT ] { %s }
}
- Functions {