Skip to content

Commit a22f9fc

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fixed bug #81457
2 parents 3240a74 + ea11e79 commit a22f9fc

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

ext/reflection/php_reflection.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,9 @@ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object)
12311231
{
12321232
reflection_object *intern;
12331233

1234-
reflection_instantiate(reflection_class_ptr, object);
1234+
zend_class_entry *reflection_ce =
1235+
ce->ce_flags & ZEND_ACC_ENUM ? reflection_enum_ptr : reflection_class_ptr;
1236+
reflection_instantiate(reflection_ce, object);
12351237
intern = Z_REFLECTION_P(object);
12361238
intern->ptr = ce;
12371239
intern->ref_type = REF_TYPE_OTHER;
@@ -1240,18 +1242,6 @@ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object)
12401242
}
12411243
/* }}} */
12421244

1243-
static void zend_reflection_enum_factory(zend_class_entry *ce, zval *object)
1244-
{
1245-
reflection_object *intern;
1246-
1247-
reflection_instantiate(reflection_enum_ptr, object);
1248-
intern = Z_REFLECTION_P(object);
1249-
intern->ptr = ce;
1250-
intern->ref_type = REF_TYPE_OTHER;
1251-
intern->ce = ce;
1252-
ZVAL_STR_COPY(reflection_prop_name(object), ce->name);
1253-
}
1254-
12551245
/* {{{ reflection_extension_factory */
12561246
static void reflection_extension_factory(zval *object, const char *name_str)
12571247
{
@@ -6849,7 +6839,7 @@ ZEND_METHOD(ReflectionEnumUnitCase, getEnum)
68496839
}
68506840
GET_REFLECTION_OBJECT_PTR(ref);
68516841

6852-
zend_reflection_enum_factory(ref->ce, return_value);
6842+
zend_reflection_class_factory(ref->ce, return_value);
68536843
}
68546844

68556845
ZEND_METHOD(ReflectionEnumBackedCase, __construct)

ext/reflection/tests/bug81457.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #81457: Enum ReflectionMethod->getDeclaringClass() return a ReflectionClass
3+
--FILE--
4+
<?php
5+
6+
enum testEnum {
7+
case A;
8+
case B;
9+
10+
public function foo () {}
11+
}
12+
13+
$re = new ReflectionEnum(testEnum::class);
14+
$me = $re->getMethod('foo');
15+
16+
echo $me->getDeclaringClass()::class, "\n";
17+
18+
$rc = new ReflectionClass(testEnum::class);
19+
$mc = $re->getMethod('foo');
20+
21+
echo $mc->getDeclaringClass()::class, "\n";
22+
23+
?>
24+
--EXPECT--
25+
ReflectionEnum
26+
ReflectionEnum

0 commit comments

Comments
 (0)