Skip to content

Autowiring should ignore optional parameters #171

Closed
@mnapoli

Description

@mnapoli

from #168

class Foo
{
    public function __construct(Bar $bar = null)
    {
        $this->bar = $bar ?: $this->createDefaultBar();
    }
}

Today, by default PHP-DI will inject a Bar instance (because of autowiring). It should instead inject the default value, unless specified otherwise.

Fixing this will be a small BC break, but I think it's a necessary evil since it's quite problematic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions