Both Symfony & Laravel allow you to never have to say specifically which class you need for a constructor, but they'll resolve it for you. When you do:
class ClassThatNeedsSomething
{
public function __construct( ServiceToLookFor $service )
..
both of them know that they need to look for an object of type ServiceToLookFor
in their service containers. Ok, but aren't classes resolved at run-time? Laravel is a framework built on top of PHP itself, it doesn't run before it and if it doesn't run before it, it means it has to instantiate itself in same environment (aka after all classes have been resolved to their files, etc.) as the others.
If there is a hook into classes such as __instantiated
so you can dynamically resolve them there, it'd make sense, but then again...where do you write the code to hook into this?
To me, it feels like a chicken & egg problem.
How is this achieved?