[php-src] Issue #8080: ReflectionClass::getConstants() gives an error depending on the order of constants definition
| From: | bsod85 | Date: | Fri, 11 Feb 2022 16:28:44 +0000 |
| Subject: | [php-src] Issue #8080: ReflectionClass::getConstants() gives an error depending on the order of constants definition | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-239681@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8080
Author: bsod85
### Description
The following code:
```php
<?php
class A {
const LIST = [
self::TEST => 'Test',
];
private const TEST = 'test';
}
class B extends A {
}
$r = new ReflectionClass(B::class);
print_r($r->getConstants());
```
Resulted in this output:
```
Fatal error: Uncaught Error: Undefined constant self::TEST in /in/FuJAW:15
Stack trace:
#0 /in/FuJAW(15): ReflectionClass->getConstants()
#1 {main}
thrown in /in/FuJAW on line 15
```
But I expected this output instead:
```
Array
(
[LIST] => Array
(
[test] => Test
)
)
```
that is the output you get by defining the constants this way:
```php
private const TEST = 'test';
const LIST = [
self::TEST => 'Test',
];
```
### PHP Version
8.1.2
### Operating System
_No response_