3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute(Attribute::TARGET_CLASS_CONSTANT)] class TestAttribute { public function __construct(public string $value) { } } enum TestNum { #[TestAttribute('alpha value')] case ALPHA; #[TestAttribute('beta value')] case BETA; } var_dump((new \ReflectionClassConstant(TestNum::class, 'ALPHA'))->getAttributes(TestAttribute::class)[0]->newInstance());
Output for 8.1.0 - 8.1.34, 8.2.21 - 8.2.30, 8.3.5 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
object(TestAttribute)#1 (1) { ["value"]=> string(11) "alpha value" }
Output for 8.0.1 - 8.0.15
Parse error: syntax error, unexpected identifier "TestNum" in /in/BsA9r on line 11
Process exited with code 255.
Output for 7.4.0 - 7.4.27
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/BsA9r on line 6
Process exited with code 255.

preferences:
62.83 ms | 925 KiB | 4 Q