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));

preferences:
23.38 ms | 404 KiB | 5 Q