[php-src] PR #25872: Fix GH-25340: ReflectionEnumBackedCase can be used on a non-backed enum via a constructor trick

From: Date: Sat, 28 Nov 2026 13:46:05 +0000
Subject: [php-src] PR #25872: Fix GH-25340: ReflectionEnumBackedCase can be used on a non-backed enum via a constructor trick
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-41155@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25872 Author: shuhuNB515 Fixes GH-25340 ## Problem When a subclass of ReflectionEnumBackedCase invokes ReflectionClassConstant::__construct() directly (bypassing the backed-enum check in ReflectionEnumBackedCase::__construct()), a subsequent call to getBackingValue() explodes: ```php <?php enum NotBacked { case A; } class FU extends ReflectionEnumBackedCase { public function __construct($class, $const) { ReflectionClassConstant::__construct($class, $const); } } (new FU('NotBacked', 'A'))->getBackingValue(); ``` - **Debug build**: ZEND_ASSERT(intern->ce->enum_backing_type != IS_UNDEF) fails. - **Release build**: zend_enum_fetch_case_value() reads property slot 1 (OBJ_PROP_NUM(zobj, 1)) of a unit enum case object, which has no such slot — an out-of-bounds read. ## Fix Replace the assertion in ReflectionEnumBackedCase::getBackingValue() with a runtime check that throws a ReflectionException ("Enum case %s::%s is not a backed case"), consistent with the error message thrown by ReflectionEnumBackedCase::__construct() and with the existing IS_UNDEF guard in _enum_case_string(). ## Verification - Reproduced the assertion failure on an unpatched debug build (PHP 8.7.0-dev). - With the patch: the repro throws Enum case NotBacked::A is not a backed case. - New test ext/reflection/tests/ReflectionEnumBackedCase_getBackingValue_003.phpt covers this. - ext/reflection suite: 570 passed, 0 failed. - Zend/tests/enum suite: 149 passed, 0 failed.

« previous php.git-pulls (#41155) next »