3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface factory { public static function new(): factory; } #[Value] class Value { public int $value; public function __construct(int $value) { $this->value = $value; } } #[Value(value: 42)] class One implements factory { public static function new(): One { return new One; } } #[Value(value: 2)] class Two implements factory { public static function new(): Two { return new Two; } } #[Value(value: 3)] class Three implements factory { public static function new(): Three { return new Three; } } $arrayOfClasses = [One::new(), Two::new(), Three::new()]; function dumpAttributeData(ReflectionClass $reflection) { $attributes = $reflection->getAttributes(); foreach ($attributes as $attribute) { var_dump($attribute->getName()); var_dump($attribute->getArguments()); } } foreach ($arrayOfClasses as $class) { dumpAttributeData(new ReflectionClass($class::class)); }
Output for 8.0.0 - 8.0.2, 8.1.23 - 8.1.28, 8.2.10 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
string(5) "Value" array(1) { ["value"]=> int(42) } string(5) "Value" array(1) { ["value"]=> int(2) } string(5) "Value" array(1) { ["value"]=> int(3) }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 string(5) "Value" array(1) { ["value"]=> int(42) } string(5) "Value" array(1) { ["value"]=> int(2) } string(5) "Value" array(1) { ["value"]=> int(3) }
Output for 7.4.0 - 7.4.15
Fatal error: Cannot use ::class with dynamic class name in /in/dt8R3 on line 62
Process exited with code 255.
Output for 7.3.0 - 7.3.27
Parse error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/dt8R3 on line 11
Process exited with code 255.

preferences:
106.02 ms | 401 KiB | 74 Q