php-fig / container

MIT License
9.93k stars 52 forks source link

Should get resolve concrete identifiers? #18

Closed deleugpn closed 7 years ago

deleugpn commented 7 years ago

According to the PSR, get will

throws an exception if the identifier is not known to the container.

Given a call to the container $container->get(Foo::class); and the fact that Some\Package\Foo is instantiable (it's a concrete class), should the container resolve it or throw NotFoundException? Of course, the scenario to be discussed is only of interest in case Foo::class has not been registered in the container before (it's unknown to the container), otherwise the question would be stupid.

namespace Some\Package;

class Foo
{

}
moufmouf commented 7 years ago

Hey @deleugpn ,

This is clearly an implementation detail.

If your container does auto-wiring (like Laravel or PHP-DI), then it makes sense to instantiate the class. If your container doesn't support auto-wiring, then it is fine to throw an exception. Different containers have different set of features and it's perfectly ok to have a different behavior based on the container you choose to use.