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

ReflectionEnumBackedCase can be used on a non-backed enum via a constructor trick

Open ndossche opened this issue 3 weeks ago • 0 comments

Description

The following code:

<?php
enum NotBacked { case A; };

class FU extends ReflectionEnumBackedCase {
    public function __construct($class, $const) {
        ReflectionClassConstant::__construct($class, $const);
    }
}

$fu = new FU('NotBacked', 'A');
$fu->getBackingValue();

Resulted in this output:

*explosion*

But I expected this output instead:

exception

PHP Version

8.4+

Operating System

No response

ndossche avatar Nov 09 '26 14:11 ndossche