Member-only story
Dependency Injection with PHP 8.4’s Lazy Objects
PHP 8.4 is out now for approximately 2 month and there are a lot of new features. One significant new feature is “Lazy Objects”, which is described as follows:
A lazy object is an object whose initialization is deferred until its state is observed or modified.
The past few weeks, I read a couple of blogs addressing Lazy Objects in the context of Dependency Injection and how it works together to boost up performance. I would like to discuss a few confusions and clarify some terminology.
This topic will also be published as a video on my YouTube channel: https://www.youtube.com/@doganoo
I will go into the topic in more detail there. So don’t forget to follow so you don’t miss anything!
Brief Recap: What is Dependency Injection
Dependency Injection (DI) is a design pattern that promotes loose coupling between components in software systems. Instead of a class creating its own dependencies, these are injected from an external source. This means a class simply declares what it needs, and another part of the application (e.g., a Dependency Injection container) provides those dependencies.
By separating the creation of dependencies from their usage, DI offers several advantages: