mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00

RFC: https://wiki.php.net/rfc/enumerations Co-authored-by: Nikita Popov <nikita.ppv@gmail.com> Closes GH-6489.
25 lines
457 B
PHP
25 lines
457 B
PHP
--TEST--
|
|
Enum case attributes
|
|
--FILE--
|
|
<?php
|
|
|
|
#[Attribute(Attribute::TARGET_CLASS_CONSTANT)]
|
|
class EnumCaseAttribute {
|
|
public function __construct(
|
|
public string $value,
|
|
) {}
|
|
}
|
|
|
|
enum Foo {
|
|
#[EnumCaseAttribute('Bar')]
|
|
case Bar;
|
|
}
|
|
|
|
var_dump((new \ReflectionClassConstant(Foo::class, 'Bar'))->getAttributes(EnumCaseAttribute::class)[0]->newInstance());
|
|
|
|
?>
|
|
--EXPECT--
|
|
object(EnumCaseAttribute)#1 (1) {
|
|
["value"]=>
|
|
string(3) "Bar"
|
|
}
|