[php-src] master: Reflection: print boolean constant values as `true` and `false`
| From: | Daniel Scherzer | Date: | Tue, 22 Sep 2026 21:09:59 +0000 |
| Subject: | [php-src] master: Reflection: print boolean constant values as `true` and `false` | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141451@lists.php.net to get a copy of this message | ||
Author: Daniel Scherzer (DanielEScherzer)
Date: 2026-09-22T13:24:10-07:00
Commit: https://github.com/php/php-src/commit/0da9d196b1621aa9549f4e98c556ffa0ee50727e
Raw diff: https://github.com/php/php-src/commit/0da9d196b1621aa9549f4e98c556ffa0ee50727e.diff
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().
Changed paths:
M Zend/tests/attributes/delayed_target_validation/has_runtime_errors.phpt
M ext/reflection/php_reflection.c
M ext/reflection/tests/ReflectionClassConstant_basic1.phpt
M ext/reflection/tests/ReflectionClassConstant_toString.phpt
M ext/reflection/tests/ReflectionConstant_toString.phpt
M ext/reflection/tests/bug29986.phpt
M ext/reflection/tests/gh22681/ReflectionClassConstant_doc_comment.phpt
M ext/reflection/tests/gh22681/ReflectionConstant_name.phpt
M sapi/cli/tests/006.phpt
Diff:
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 [ <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 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 [ <user> 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 [ <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 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..af9c8f8eb81e 100644
--- a/sapi/cli/tests/006.phpt
+++ b/sapi/cli/tests/006.phpt
@@ -63,7 +63,7 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
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 {