Fix #81681: ReflectionEnum throwing exceptions

Enums are neither instantiable nor cloneable.

Closes GH-7707.
This commit is contained in:
Christoph M. Becker 2021-12-02 19:05:34 +01:00
parent 9a3ca278b3
commit 59dd4fd742
No known key found for this signature in database
GPG Key ID: D66C9593118BCCB6
3 changed files with 22 additions and 2 deletions

2
NEWS
View File

@ -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

View File

@ -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;
}
@ -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)) {

View File

@ -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)