Skip to content

Commit 0615184

Browse files
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()`.
1 parent 3baad7a commit 0615184

9 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎Zend/tests/attributes/delayed_target_validation/has_runtime_errors.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ array(2) {
265265
}
266266
Error: Attribute "Attribute" cannot target function (allowed targets: class)
267267
********************
268-
Constant [ bool EXAMPLE ] { 1 }
268+
Constant [ bool EXAMPLE ] { true }
269269

270270
array(2) {
271271
[0]=>

‎ext/reflection/php_reflection.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,10 @@ static void _const_string(smart_str *str, const zend_string *name, const zval *v
594594
smart_str_append(str, Z_STR_P(value));
595595
} else if (Z_TYPE_P(value) == IS_DOUBLE) {
596596
smart_str_append_double(str, Z_DVAL_P(value), (int) EG(precision), false);
597+
} else if (Z_TYPE_P(value) == IS_FALSE) {
598+
smart_str_append(str, ZSTR_KNOWN(ZEND_STR_FALSE));
599+
} else if (Z_TYPE_P(value) == IS_TRUE) {
600+
smart_str_append(str, ZSTR_KNOWN(ZEND_STR_TRUE));
597601
} else {
598602
zend_string *tmp_value_str;
599603
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
630634
smart_str_appends(str, "Object");
631635
} else if (Z_TYPE(c->value) == IS_DOUBLE) {
632636
smart_str_append_double(str, Z_DVAL(c->value), (int) EG(precision), false);
637+
} else if (Z_TYPE(c->value) == IS_FALSE) {
638+
smart_str_append(str, ZSTR_KNOWN(ZEND_STR_FALSE));
639+
} else if (Z_TYPE(c->value) == IS_TRUE) {
640+
smart_str_append(str, ZSTR_KNOWN(ZEND_STR_TRUE));
633641
} else {
634642
zend_string *tmp_value_str;
635643
zend_string *value_str = zval_get_tmp_string(&c->value, &tmp_value_str);

‎ext/reflection/tests/ReflectionClassConstant_basic1.phpt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ reflectClassConstant($instance, "BAD_CONST");
5757
Reflecting on class constant TestClass::PUB
5858

5959
__toString():
60-
string(57) "/** My Doc comment */
61-
Constant [ public bool PUB ] { 1 }
60+
string(60) "/** My Doc comment */
61+
Constant [ public bool PUB ] { true }
6262
"
6363
getName():
6464
string(3) "PUB"

‎ext/reflection/tests/ReflectionClassConstant_toString.phpt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ echo new ReflectionClass(Demo::class);
1515

1616
?>
1717
--EXPECTF--
18-
Constant [ public bool IS_TRUE ] { 1 }
19-
Constant [ public bool IS_FALSE ] { }
18+
Constant [ public bool IS_TRUE ] { true }
19+
Constant [ public bool IS_FALSE ] { false }
2020
Class [ <user> class Demo ] {
2121
@@ %s %d-%d
2222

2323
- Constants [2] {
24-
Constant [ public bool IS_TRUE ] { 1 }
25-
Constant [ public bool IS_FALSE ] { }
24+
Constant [ public bool IS_TRUE ] { true }
25+
Constant [ public bool IS_FALSE ] { false }
2626
}
2727

2828
- Static properties [0] {

‎ext/reflection/tests/ReflectionConstant_toString.phpt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ echo new ReflectionConstant('IS_FALSE');
1111

1212
?>
1313
--EXPECT--
14-
Constant [ bool IS_TRUE ] { 1 }
15-
Constant [ bool IS_FALSE ] { }
14+
Constant [ bool IS_TRUE ] { true }
15+
Constant [ bool IS_FALSE ] { false }

‎ext/reflection/tests/bug29986.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Class [ <user> class just_constants ] {
2020
@@ %s %d-%d
2121

2222
- Constants [5] {
23-
Constant [ public bool BOOLEAN_CONSTANT ] { 1 }
23+
Constant [ public bool BOOLEAN_CONSTANT ] { true }
2424
Constant [ public null NULL_CONSTANT ] { }
2525
Constant [ public string STRING_CONSTANT ] { This is a string }
2626
Constant [ public int INTEGER_CONSTANT ] { 1000 }

‎ext/reflection/tests/gh22681/ReflectionClassConstant_doc_comment.phpt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ echo new ReflectionClass(Demo::class);
2020
?>
2121
--EXPECTF--
2222
/** F%0oo */
23-
Constant [ public bool DEMO ] { 1 }
23+
Constant [ public bool DEMO ] { true }
2424
string(11) "/** F%0oo */"
2525
Class [ <user> class Demo ] {
2626
@@ %s(%d) : eval()'d code %d-%d
2727

2828
- Constants [1] {
2929
/** F%0oo */
30-
Constant [ public bool DEMO ] { 1 }
30+
Constant [ public bool DEMO ] { true }
3131
}
3232

3333
- Static properties [0] {

‎ext/reflection/tests/gh22681/ReflectionConstant_name.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ var_dump( $r->getName() );
1111

1212
?>
1313
--EXPECTF--
14-
Constant [ bool F%0oo ] { 1 }
14+
Constant [ bool F%0oo ] { true }
1515
string(4) "F%0oo"

‎sapi/cli/tests/006.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
6363
Constant [ <persistent> string PCRE_VERSION ] { %s }
6464
Constant [ <persistent> int PCRE_VERSION_MAJOR ] { %d }
6565
Constant [ <persistent> int PCRE_VERSION_MINOR ] { %d }
66-
Constant [ <persistent> bool PCRE_JIT_SUPPORT ] { %d }
66+
Constant [ <persistent> bool PCRE_JIT_SUPPORT ] { %s }
6767
}
6868

6969
- Functions {

0 commit comments

Comments
 (0)