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; } $obj = TestNum::ALPHA; var_dump((new \ReflectionClassConstant($obj::class, $obj->name))->getAttributes(TestAttribute::class)[0]->newInstance());
Output for 8.1.0 - 8.1.33, 8.2.21 - 8.2.29, 8.3.5 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
object(TestAttribute)#2 (1) { ["value"]=> string(11) "alpha value" }
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.0.1 - 8.0.15
Parse error: syntax error, unexpected identifier "TestNum" in /in/YY6Oa 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/YY6Oa on line 6
Process exited with code 255.

preferences:
86.41 ms | 410 KiB | 5 Q