3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); class One { public function test() :?DateTimeImmutable { return rand(0,1) === 1 ? new DateTimeImmutable(): null; } } class Two { public function test(): void { $test = new One(); echo $test->test() ? $test->test()->format('d') : null; } } $two = new Two(); $two->test();

preferences:
19.53 ms | 402 KiB | 5 Q