Skip to content

Commit

Permalink
Fix #81681: ReflectionEnum throwing exceptions
Browse files Browse the repository at this point in the history
Enums are neither instantiable nor cloneable.

Closes GH-7707.
  • Loading branch information
cmb69 committed Dec 2, 2021
1 parent 9a3ca27 commit 59dd4fd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.2

- Reflection:
. Fixed bug #81681 (ReflectionEnum throwing exceptions). (cmb)

02 Dec 2021, PHP 8.1.1

Expand Down
4 changes: 2 additions & 2 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -4751,7 +4751,7 @@ ZEND_METHOD(ReflectionClass, isInstantiable)
RETURN_THROWS();
}
GET_REFLECTION_OBJECT_PTR(ce);
if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) {
if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_ENUM)) {
RETURN_FALSE;
}

Expand All @@ -4776,7 +4776,7 @@ ZEND_METHOD(ReflectionClass, isCloneable)
RETURN_THROWS();
}
GET_REFLECTION_OBJECT_PTR(ce);
if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) {
if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_ENUM)) {
RETURN_FALSE;
}
if (!Z_ISUNDEF(intern->obj)) {
Expand Down
18 changes: 18 additions & 0 deletions ext/reflection/tests/bug81681.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Bug #81681 (ReflectionEnum throwing exceptions)
--FILE--
<?php
enum Status
{
case Draft;
case Published;
case Archived;
}

$reflectionEnum = new \ReflectionEnum('\Status');
var_dump($reflectionEnum->isInstantiable());
var_dump($reflectionEnum->isCloneable());
?>
--EXPECT--
bool(false)
bool(false)

0 comments on commit 59dd4fd

Please sign in to comment.