// *** before: ***
class Report {
private ?array $rows = null;
public function getRows(): array {
// manual lazy-loading through a nullable backing field
if ($this->rows === null) {
$this->rows = $this->loadFromDatabase();
}
return $this->rows;
}
}
// *** in version 8.4: ***
$reflector = new ReflectionClass(Report::class);
$report = $reflector->newLazyGhost(function (Report $report) {
// runs only on the first access to a property or method of $report
$report->__construct($this->loadFromDatabase());
});