[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] [php-src] master: Merge branch 'PHP-8.1'
From:       Ilija Tovilo <noreply () php ! net>
Date:       2022-04-29 8:26:10
Message-ID: hCIH3ekZPKEW6lpZzJYj2nVYXWFyne8p23TCmjtwhQ () main ! php ! net
[Download RAW message or body]

Author: Ilija Tovilo (iluuu1994)
Date: 2022-04-29T10:22:08+02:00

Commit: https://github.com/php/php-src/commit/90a845c13f88072af3cc048731936e4a61b3ec3a
Raw diff: https://github.com/php/php-src/commit/90a845c13f88072af3cc048731936e4a61b3ec3a.diff

Merge branch 'PHP-8.1'

* PHP-8.1:
  Fix ReflectionProperty::__toString() of properties containing enums

Changed paths:
  A  ext/reflection/tests/gh8444.phpt
  M  ext/reflection/php_reflection.c


Diff:

diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index bfa3073bb96b..33ec42c75794 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -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), "");
diff --git a/ext/reflection/tests/gh8444.phpt b/ext/reflection/tests/gh8444.phpt
new file mode 100644
index 000000000000..9629a8db3817
--- /dev/null
+++ b/ext/reflection/tests/gh8444.phpt
@@ -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] ]

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic