3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Command { public function run(): int { return $this->execute(); } protected function execute(): int { throw new LogicException('You must override the execute() method in the concrete command class.'); } } class FooCommand extends Command { protected function execute(): int { echo "Executing FooCommand\n"; return 0; } } class BarCommand extends Command { public function __construct(private readonly FooCommand $command) { } protected function execute(): int { $this->command->execute(); echo "Executing BarCommand\n"; return 0; } } $command = new BarCommand(new FooCommand()); $command->run();
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Executing FooCommand Executing BarCommand

preferences:
72.73 ms | 406 KiB | 5 Q