Hi there 👋
It is all about recently updated PHPdoc for Container::get
/**
* Returns an entry of the container by its name.
*
* @template T
* @param string|class-string<T> $id Entry name or a class name.
*
* @return ($id is class-string<T> ? T : mixed)
* @throws DependencyException Error while resolving the entry.
* @throws NotFoundException No entry found for the given name.
*/
public function get(string $id) : mixed
There is nothing preventing one to do $container->set(MyClass::class, "not my class type").
Therefore it is misleading pretending that $container->get(MyClass::class) will always return an instance of MyClass.
I had this unexpected behavior for I explicitly disable a class injection is a given context by doing $container->set(MyClass::class, null). And the class-name is still registered and getting it will return null and will not throw an exception.
With the v7.0.10, phpstan started telling my i do not need a nullsafe operand when using the $container->get(MyClass::class) result.
I would recommend reverting #912
Cheers and thank you for your work !
Hi there 👋
It is all about recently updated PHPdoc for
Container::getThere is nothing preventing one to do
$container->set(MyClass::class, "not my class type").Therefore it is misleading pretending that
$container->get(MyClass::class)will always return an instance ofMyClass.I had this unexpected behavior for I explicitly disable a class injection is a given context by doing
$container->set(MyClass::class, null). And the class-name is still registered and getting it will return null and will not throw an exception.With the
v7.0.10, phpstan started telling my i do not need a nullsafe operand when using the$container->get(MyClass::class)result.I would recommend reverting #912
Cheers and thank you for your work !