Explain the concept of 'Ghost Objects' (Lazy Objects) in PHP 8.4 and their use case in ORMs.

Last updated 15 June 2026

  • Lazy Objects defer initialization until a property is first accessed. They are created via reflection (e.g. newLazyGhost()) with an initializer closure.

  • A ghost is the real class instance initialized in place, while a lazy proxy forwards to a separately created instance.

  • ORMs can return related entities (e.g. an order's $customer) without querying until fields are read, replacing hand-written proxy classes.

  • https://www.php.net/manual/en/language.oop5.lazy-objects.php
  • https://chrastecky.dev/programming/lazy-objects-in-php-8-4
  • https://tideways.com/profiler/blog/lazy-loading-data-objects-in-php-8-4-with-doctrine-orm-example
  • https://www.youtube.com/watch?v=X0HhrOnkGlc
  • https://www.doctrine-project.org/2025/06/28/orm-3.4.0-released.html
  • https://wiki.php.net/rfc/lazy-objects
  • https://stitcher.io/blog/new-in-php-84
All PHP interview questions