3v4l.org

run code in 300+ PHP versions simultaneously
<?php final readonly class TestObject { public function __construct(public int $number) { echo "Constructor called\n"; } public function getLucky(): void { echo "Your lucky number: $this->number\n"; } } $lazy = new ReflectionClass(TestObject::class)->newLazyGhost(function (TestObject $object) { $object->__construct(42); }); echo "Object created\n"; $lazy->getLucky();
Output for 8.4.1 - 8.4.8
Object created Constructor called Your lucky number: 42
Output for 8.2.0 - 8.2.28, 8.3.0 - 8.3.22
Parse error: syntax error, unexpected token "->" in /in/DW2lp on line 13
Process exited with code 255.

preferences:
155.14 ms | 997 KiB | 7 Q