Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

How native lazy objects will change Doctrine an...

How native lazy objects will change Doctrine and Symfony forever

Starting with PHP 8.4 you can implement lazy loading and proxy objects with native PHP functionality with little overhead and no code generation required. Both Doctrine and Symfony are historically using the proxy pattern with solutions and workarounds built in PHP. In this talk I will explain PHPs 8.4s native lazy objects and how it will be a game changer to both Doctrine and Symfony going forward.

Avatar for Benjamin Eberlei

Benjamin Eberlei

November 28, 2025
Tweet

More Decks by Benjamin Eberlei

Other Decks in Technology

Transcript

  1. Mental Model: Think of lazy objects as deferring the construction

    of an object to the first point where it’s actually used.
  2. ❌ get_class($proxy) === User::class ❌ final class User ⚠️ readonly

    & Property Hooks ❌ No code generation ✅ same object comparison (===)
  3. ✅ get_class($proxy) === User::class ✅ final class User ✅ readonly

    & Property Hooks ✅ No code generation ✅ same object comparison (===)
  4. The proxy object is _not_ replaced or substituted for the

    real instance. After initialization, property accesses on the proxy are forwarded to the real instance.
  5. ✅ get_class($proxy) === User::class ✅ final class User ✅ readonly

    & Property Hooks ✅ No code generation ⚠️ same object comparison (===)
  6. Initialization Triggers Reading or writing a property Testing if a

    property is set or unsetting it Calling ReflectionProperty::get[Raw]Value() and set[Raw]Value() Calling ReflectionObject::getProperties() or ReflectionObject::getProperty() Cloning
  7. The following special cases do not trigger initialization of a

    lazy object: Calls to get_mangled_object_vars() serialize(), var_dump() in some cases Casting to array using the (array) operator. Calls to ReflectionObject::__toString().