3v4l.org

run code in 300+ PHP versions simultaneously
<?php final readonly class Client { public function __construct( private string $a, private string $very, private string $long, private string $list, private string $of, private string $constructor, private string $argument, private string $userAgent, ) { } public function fetch(int $id): array { var_dump("fetching user $id"); // Simulate fetching from remote service $this->userAgent; return [ 'id' => $id, 'name' => 'John Doe', ]; } public function getName(): string { return 'The Super API Client'; } } final readonly class UserRepository { public function __construct( public Client $client, ) { } public function find(int $id): array { return $this->client->fetch($id); } } $reflector = new ReflectionClass(Client::class); $client = $reflector->newLazyProxy(function ($x) { var_dump("init"); return new Client( 'a', 'very', 'long', 'list', 'of', 'constructor', 'argument', 'Mozilla/5.0', ); }); $repository = new UserRepository($client); var_dump($repository->client->getName()); var_dump($repository->find(42));
Output for 8.4.1 - 8.4.14, 8.5.0
string(20) "The Super API Client" string(16) "fetching user 42" string(4) "init" array(2) { ["id"]=> int(42) ["name"]=> string(8) "John Doe" }
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.2.23 - 8.2.29, 8.3.5 - 8.3.28
Fatal error: Uncaught Error: Call to undefined method ReflectionClass::newLazyProxy() in /in/S6B46:50 Stack trace: #0 {main} thrown in /in/S6B46 on line 50
Process exited with code 255.
Output for 8.1.30 - 8.1.33
Parse error: syntax error, unexpected token "readonly", expecting "abstract" or "final" or "class" in /in/S6B46 on line 3
Process exited with code 255.

preferences:
44.08 ms | 410 KiB | 5 Q