3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Command{ /** @var callable $code */ private $code; /** * @param callable $code */ public function setCode(callable $code): static { $this->code = $code; return $this; } public function execute(): void { ($this->code)(); } } class CustomCommand extends Command{ public function __construct(){ parent::setCode([$this, 'runCustomCommand']); } protected function runCustomCommand(): void { echo 'Protected function called'; } } $code = new CustomCommand(); $code->execute();
Output for 8.1.0 - 8.1.29, 8.2.0 - 8.2.22, 8.3.0 - 8.3.10
Protected function called

preferences:
52.29 ms | 406 KiB | 5 Q