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_* 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 new file mode 100644 index 000000000000..83c513e8b42c --- /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 ] { true } +Constant [ public bool IS_FALSE ] { false } +Class [ class Demo ] { + @@ %s %d-%d + + - Constants [2] { + Constant [ public bool IS_TRUE ] { true } + Constant [ public bool IS_FALSE ] { 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..c60a8252d22b --- /dev/null +++ b/ext/reflection/tests/ReflectionConstant_toString.phpt @@ -0,0 +1,15 @@ +--TEST-- +ReflectionConstant::__toString() +--FILE-- + +--EXPECT-- +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 {