Skip to content

Throw an exception if unknown parameter passed to a method #96

@BoShurik

Description

@BoShurik

What steps will reproduce the problem?

class Foo
{
    public function __construct(public Bar $bar)
    {
    }
}

class Bar
{
    public function __construct(public string $value = 'default')
    {
    }
}

$config = ContainerConfig::create()
    ->withDefinitions([
        Foo::class => [
            'class' => Foo::class,
            '__construct()' => [
                'baz' => Reference::to('bar'), // Typo here
            ],
        ],
        'bar' => [
            'class' => Bar::class,
            '__construct()' => [
                'value' => 'custom',
            ],
        ],
    ]);

$container = new Container($config);

var_dump($container->get(Foo::class));

What is the expected result?

Exception with message, like:
Unknown parameter $baz in Foo::__construct() method. Available paraemeters: $bar

What do you get instead?

New instance of Foo with wrong Bar

class Foo#11 (1) {
  public Bar $bar =>
  class Bar#10 (1) {
    public string $value =>
    string(7) "default"
  }
}

Additional info

Q A
Version master
PHP version N/A
Operating system N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions