php-src icon indicating copy to clipboard operation
php-src copied to clipboard

isCloneable() on ReflectionEnum errors

Open Crell opened this issue 4 years ago • 1 comments

Description

The following code:

<?php

enum A {
    case B;
}

$e = new ReflectionEnum(A::class);
var_dump($e->isCloneable());


$c = new ReflectionClass(A::class);
var_dump($c->isCloneable());

Resulted in this output:

Fatal error: Uncaught Error: Cannot instantiate enum A in /in/IIhNF:8
Stack trace:
#0 /in/IIhNF(8): ReflectionClass->isCloneable()
#1 {main}
  thrown in /in/IIhNF on line 8

But I expected this output instead:

false
false

Right now, isCloneable() errors out on an Enum, regardless of whether it is called on ReflectionEnum or ReflectionClass. (The former is a child of the latter, so it's possible to reflect on an Enum with either Reflection class.) Since enums are not cloneable, I would expect it to simply return false in both cases.

PHP Version

8.1.1

Operating System

No response

Crell avatar Jan 05 '22 20:01 Crell

Duplicate of bug 81681 which will be fixed in 8.1.2.

damianwadley avatar Jan 05 '22 20:01 damianwadley