3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Acme { public function __construct( public readonly int $changeMe, ) {} } $object = new Acme(1); $reflection = new ReflectionClass($object); $instance = $reflection->newInstanceWithoutConstructor(); $reflectionProperty = $reflection->getProperty('changeMe'); $reflectionProperty->setValue($instance, 33); var_dump($reflectionProperty->getValue($instance));
Output for 8.1.0 - 8.1.26, 8.2.0 - 8.2.15, 8.3.0 - 8.3.2
int(33)
Output for 8.0.1 - 8.0.30
Parse error: syntax error, unexpected identifier "int", expecting variable in /in/mis1l on line 5
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/mis1l on line 5
Process exited with code 255.

preferences:
339.51 ms | 1399 KiB | 114 Q