[php-src] Issue #20999: How to intercept in advance?

[email protected] (wheakerd)
Newsgroups php.bugs
Message-ID <[email protected]>
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)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.