3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); namespace Monolog\Handler; class LogRecord implements \ArrayAccess { public function __construct( public readonly string $message, public readonly int $level, public readonly array $context, public array $extra, // only field that is modifiable in theory ) {} // ... public function offsetSet(mixed $offset, mixed $value): void { if (is_null($offset)) { throw new \LogicException('Unsupported operation'); } else { $this->{$offset} = $value; } } public function offsetExists(mixed $offset): bool { return isset($this->{$offset}); } public function offsetUnset(mixed $offset): void { throw new \LogicException('Unsupported operation'); } public function offsetGet(mixed $offset): mixed { return $this->{$offset} ?? null; } } // Record for forward-compat in V2 would be added as: // interface Record implements \ArrayAccess {} interface HandlerInterfaceV2 { public function handle(array $record): bool; } interface HandlerInterfaceV3 { public function handle(LogRecord $record): bool; } class HandlerCompatPHP81OnV2 implements HandlerInterfaceV2 { public function handle(array|LogRecord $record): bool { echo $record['message']; return false; } } class HandlerCompatPHP81OnV3 implements HandlerInterfaceV3 { public function handle(array|LogRecord $record): bool { echo $record['message']; return false; } } class HandlerCompatOnV2 implements HandlerInterfaceV2 { public function handle($record): bool { echo $record['message']; return false; } } class HandlerCompatOnV3 implements HandlerInterfaceV3 { public function handle($record): bool { echo $record['message']; return false; } } class HandlerV2Only implements HandlerInterfaceV2 { public function handle(array $record): bool { echo $record['message']; return false; } } class HandlerV3Only implements HandlerInterfaceV3 { public function handle(LogRecord $record): bool { echo $record->message; return false; } } $record = new LogRecord('foo', 100, [], []); $handler = new HandlerCompatOnV3; $handler->handle($record); $handler = new HandlerV3Only; $handler->handle($record);
Output for 8.1.3 - 8.1.34, 8.2.23 - 8.2.31, 8.3.5 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
foofoo

preferences:
73.57 ms | 749 KiB | 4 Q