3v4l.org

run code in 500+ 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; } $obj = TestNum::ALPHA; $reflection = new ReflectionClass($obj); $classAttributes = $reflection->getAttributes(TestAttribute::class); var_dump($classAttributes);
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.31, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
array(0) { }
Output for 8.0.1 - 8.0.30
Parse error: syntax error, unexpected identifier "TestNum" in /in/uLDVQ on line 11
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/uLDVQ on line 6
Process exited with code 255.

preferences:
56.13 ms | 1267 KiB | 4 Q