Skip to content

Commit 59dd4fd

Browse files
committed
Fix #81681: ReflectionEnum throwing exceptions
Enums are neither instantiable nor cloneable. Closes phpGH-7707.
1 parent 9a3ca27 commit 59dd4fd

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.2
44

5+
- Reflection:
6+
. Fixed bug #81681 (ReflectionEnum throwing exceptions). (cmb)
57

68
02 Dec 2021, PHP 8.1.1
79

ext/reflection/php_reflection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,7 +4751,7 @@ ZEND_METHOD(ReflectionClass, isInstantiable)
47514751
RETURN_THROWS();
47524752
}
47534753
GET_REFLECTION_OBJECT_PTR(ce);
4754-
if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) {
4754+
if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_ENUM)) {
47554755
RETURN_FALSE;
47564756
}
47574757

@@ -4776,7 +4776,7 @@ ZEND_METHOD(ReflectionClass, isCloneable)
47764776
RETURN_THROWS();
47774777
}
47784778
GET_REFLECTION_OBJECT_PTR(ce);
4779-
if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) {
4779+
if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_ENUM)) {
47804780
RETURN_FALSE;
47814781
}
47824782
if (!Z_ISUNDEF(intern->obj)) {

ext/reflection/tests/bug81681.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #81681 (ReflectionEnum throwing exceptions)
3+
--FILE--
4+
<?php
5+
enum Status
6+
{
7+
case Draft;
8+
case Published;
9+
case Archived;
10+
}
11+
12+
$reflectionEnum = new \ReflectionEnum('\Status');
13+
var_dump($reflectionEnum->isInstantiable());
14+
var_dump($reflectionEnum->isCloneable());
15+
?>
16+
--EXPECT--
17+
bool(false)
18+
bool(false)

0 commit comments

Comments
 (0)