- rand: documentation ( source)
<?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();