Revisiting Lazy-Loading Proxies in PHP

  • You can find lazy services in e.g. the Symfony dependency-injection container. Here is an excerpt from the documentation:
    Imagine you have a NewsletterManager and you inject a mailer service into it. Only a few methods on your NewsletterManager actually use the mailer, but even when you don't need it, a mailer service is always instantiated in order to construct your NewsletterManager.
    By making it lazy, the mailer service won't be initialized unless NewsletterManager actually sends an email.
  • You can find lazy entities in e.g. Doctrine ORM where they’re used to create entities and collections that aren’t yet populated. Only when first-accessing any of their properties will lazy-initialization retrieve their state by doing SQL queries.
  1. to support a wide range of PHP and Composer versions,
  2. to fix some behaviors that used to require monkey-patching on the side of proxy-manager-bridge (e.g. skipping destructors on uninitialized instances or compatibility with fluent APIs),
  3. and to support newer PHP versions (to date, ProxyManager doesn't support PHP 8.1 but we require this version in Symfony 6.1.)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nicolas Grekas

Nicolas Grekas

1K Followers

Loves clean architecture, best performance, fast CI, great developer experience. Shipping as Symfony core team member, Blackfire.io CTO, ESPCI Alumni.