Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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_*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]=>
Expand Down
8 changes: 8 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ext/reflection/tests/ReflectionClassConstant_basic1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
39 changes: 39 additions & 0 deletions ext/reflection/tests/ReflectionClassConstant_toString.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
ReflectionClassConstant::__toString() and class constant display
--FILE--
<?php

class Demo {
public const IS_TRUE = true;
public const IS_FALSE = false;
}

echo new ReflectionClassConstant(Demo::class, 'IS_TRUE');
echo new ReflectionClassConstant(Demo::class, 'IS_FALSE');

echo new ReflectionClass(Demo::class);

?>
--EXPECTF--
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 ] { true }
Constant [ public bool IS_FALSE ] { false }
}

- Static properties [0] {
}

- Static methods [0] {
}

- Properties [0] {
}

- Methods [0] {
}
}
15 changes: 15 additions & 0 deletions ext/reflection/tests/ReflectionConstant_toString.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
ReflectionConstant::__toString()
--FILE--
<?php

const IS_TRUE = true;
const IS_FALSE = false;

echo new ReflectionConstant('IS_TRUE');
echo new ReflectionConstant('IS_FALSE');

?>
--EXPECT--
Constant [ bool IS_TRUE ] { true }
Constant [ bool IS_FALSE ] { false }
2 changes: 1 addition & 1 deletion ext/reflection/tests/bug29986.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ var_dump( $r->getName() );

?>
--EXPECTF--
Constant [ bool F%0oo ] { 1 }
Constant [ bool F%0oo ] { true }
string(4) "F%0oo"
2 changes: 1 addition & 1 deletion sapi/cli/tests/006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] { true }
}

- Functions {
Expand Down
Loading