newLazyGhost( static function (Report $report) use (&$attempts): void { ++$attempts; $report->title = 'Incomplete'; if ($attempts === 1) { throw new RuntimeException('first load failed'); } $report->title = 'Recovered'; } ); try { echo $report->title, PHP_EOL; } catch (RuntimeException $error) { echo 'caught: ', $error->getMessage(), PHP_EOL; } echo $report->title, PHP_EOL; echo $report->title, PHP_EOL; echo 'attempts=', $attempts, PHP_EOL;