Extending a definition and overriding the concrete may have no effect
jleeothon opened this issue · comments
Johnny Lee-Othon commented
I'm using league/container=3.2.2
<?php
require_once 'vendor/autoload.php';
use League\Container\Container;
class MyClass {}
class MyClass2 {}
$container = new Container();
$container->share('a', new MyClass());
var_dump($container->get('a'));
// object(MyClass)#6 (0) {
// }
$container->extend('a')->setConcrete(new MyClass2());
var_dump($container->get('a'));
// Actual:
// object(MyClass)#6 (0) {
// }
// Expected:
// object(MyClass2)#7 (0) {
// }
If I understand correctly, this may happen because when updating the $concrete
, the $resolved
member is not updated to null
.
Daniel Opitz commented
Hello!
I need this functionality for my unit tests, because I have to overwrite some of the container definitions like the logger, the session and the database connection...
I would be very thankful for merging this fix. :-)
Phil Bennett commented
Fixed by #172