Skip to content

Extend a previous object definition to add method calls #349

@mopahle

Description

@mopahle

DI\object()->method() behaves somewhat unexpected when extending objects.
Here is an example:

// definitions1.php
return [
    MyClass::class=>DI\object()
        ->method('setConfiguration', 'a config value')
        ->method('addSomething', 'something')
        ->method('addSomething', 'another something')
];

// definitions2.php
return [
    MyClass::class=>DI\object()
        ->method('setConfiguration', 'a new config value')
        ->method('addSomething', 'just another something')
];

My expectation was, that "addSomething" is called three times but it is not. In fact the first call with "something" is replaced with "just another something". I know that this is great if you set something and want to override the value later. But what is the right way to explicitly add a method call?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions