[php-src] Issue #20999: How to intercept in advance?
| From: | wheakerd | Date: | Thu, 22 Jan 2026 01:11:51 +0000 |
| Subject: | [php-src] Issue #20999: How to intercept in advance? | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251587@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/20999
Author: wheakerd
### Description
The following code:
```php
<?php
declare(strict_types=1);
final class ReflectorCollector
{
private static array $reflections = [
'class' => [],
'class_constant' => [],
'constant' => [],
'enum' => [],
'enum_units' => [],
'enum_backed_cases' => [],
];
public static function reflectEnum(string $class): ReflectionEnum
{
if (!isset(self::$reflections['enum'][$class])) {
if (!enum_exists($class)) {
throw new ReflectorException("The enum \"$class\" does not exist.");
}
self::$reflections['enum'][$class] = new ReflectionEnum($class);
}
return self::$reflections['enum'][$class];
}
public static function reflectEnumUnitCase(string $class, string $constant): ReflectionEnumUnitCase
{
if (!isset(self::$reflections['enum_units']["$class::$constant"])) {
$reflectionEnum = self::reflectEnum($class);
if (!$reflectionEnum->hasCase($constant)) {
throw new ReflectorException("The case \"$constant\" does not exist in enum
\"$class\".");
}
// see here
self::$reflections['enum_units']["$class::$constant"] =
$reflectionEnum->getCase($constant);
}
return self::$reflections['enum_units']["$class::$constant"];
}
}
```
Resulted in this output:
```
Why might
self::$reflections['enum_units']["$class::$constant"] =
$reflectionEnum->getCase($constant); throw an exception?
```
But I expected this output instead:
```
No exception was thrown.
```
### PHP Version
```plain
PHP 8.4.14 (cli) (built: Oct 25 2025 03:34:16) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.14, Copyright (c) Zend Technologies
```
### Operating System
24.04.3 LTS (Noble Numbat)