auraphp / Aura.Di

Dependency Injection System
MIT License
349 stars 63 forks source link

Probably wrong auto-resolution of typed parameter with default value #165

Closed denfil closed 5 years ago

denfil commented 6 years ago

Here is code example:

class Foo {}

class Test {
    public function __construct(Foo $foo = null) {
        var_dump($foo);
    }
}

class Config extends Aura\Di\ContainerConfig {
    public function define(Aura\Di\Container $di)  {
        $di->types[Foo::class] = $di->lazyNew(Foo::class);
    }
}

(new Aura\Di\ContainerBuilder())
    ->newConfiguredInstance(
        [Config::class],
        Aura\Di\ContainerBuilder::AUTO_RESOLVE
    )->newInstance(Test::class);

In this case Aura.Di doesn't resolve parameter and output will be NULL. But if we remove default value __construct(Foo $foo) then Aura.Di will succesfully resolve parameter and output will be object(Foo)#11 (0) {}

Is it a bug or a feature?

harikt commented 5 years ago

@frederikbosch is there a way we can resolve it for 3.x with the same technique ? Else we can close this and move with 4.x .

frederikbosch commented 5 years ago

Created another PR. As soon as the Travis lights are green, I will merge it in.

frederikbosch commented 5 years ago

Closed via #180 and #179.