mirror of
https://github.com/php/php-src.git
synced 2024-11-27 11:53:33 +08:00
Fix ReflectionProperty::__toString() of properties containing enums
Fix GH-8444
This commit is contained in:
parent
21d551ad0f
commit
1944c14ce7
2
NEWS
2
NEWS
@ -141,6 +141,8 @@ PHP NEWS
|
||||
- Reflection:
|
||||
. Fixed bug GH-8080 (ReflectionClass::getConstants() depends on def. order).
|
||||
(cmb)
|
||||
. Fixed bug GH-8444 (Fix ReflectionProperty::__toString() of properties
|
||||
containing instantiated enums). (ilutov)
|
||||
|
||||
- Zlib:
|
||||
. Fixed bug GH-7953 (ob_clean() only does not set Content-Encoding). (cmb)
|
||||
|
@ -638,6 +638,13 @@ static int format_default_value(smart_str *str, zval *value) {
|
||||
format_default_value(str, zv);
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
smart_str_appendc(str, ']');
|
||||
} else if (Z_TYPE_P(value) == IS_OBJECT) {
|
||||
zend_object *obj = Z_OBJ_P(value);
|
||||
zend_class_entry *class = obj->ce;
|
||||
ZEND_ASSERT(class->ce_flags & ZEND_ACC_ENUM);
|
||||
smart_str_append(str, class->name);
|
||||
smart_str_appends(str, "::");
|
||||
smart_str_append(str, Z_STR_P(zend_enum_fetch_case_name(obj)));
|
||||
} else {
|
||||
ZEND_ASSERT(Z_TYPE_P(value) == IS_CONSTANT_AST);
|
||||
zend_string *ast_str = zend_ast_export("", Z_ASTVAL_P(value), "");
|
||||
|
31
ext/reflection/tests/gh8444.phpt
Normal file
31
ext/reflection/tests/gh8444.phpt
Normal file
@ -0,0 +1,31 @@
|
||||
--TEST--
|
||||
GH-8444 (Fix ReflectionProperty::__toString() of properties containing instantiated enums)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
enum Foo
|
||||
{
|
||||
case Bar;
|
||||
}
|
||||
|
||||
class Bar
|
||||
{
|
||||
public Foo $enum = Foo::Bar;
|
||||
public $enumInArray = [Foo::Bar];
|
||||
}
|
||||
|
||||
echo new \ReflectionProperty('Bar', 'enum'), "\n";
|
||||
echo new \ReflectionProperty('Bar', 'enumInArray'), "\n";
|
||||
|
||||
echo new \ReflectionProperty(new Bar, 'enum'), "\n";
|
||||
echo new \ReflectionProperty(new Bar, 'enumInArray'), "\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Property [ public Foo $enum = Foo::Bar ]
|
||||
|
||||
Property [ public $enumInArray = [Foo::Bar] ]
|
||||
|
||||
Property [ public Foo $enum = Foo::Bar ]
|
||||
|
||||
Property [ public $enumInArray = [Foo::Bar] ]
|
Loading…
Reference in New Issue
Block a user