Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Order of how arguments are merged in multiple di.xml-files causes unexpected results #8647
Ok, so bear with me on this one. I have to explain some things first because I have no other way on explaining what's this issue is about, although in my opinion it's quite an important one.
How Magento handles constructor arguments
Take a look at the following example about 2 modules, module A and B, that want to add some arguments to an argument in module X:
The above 2 configurations both manipulate the argument named
Under the hood
Let me explain some code that's currently in Magento 2: Take a look at the method
This code is (or one of the parts of) responsible for smashing down the various
However... This could have some unexpected side-effects.
A theoretical example
Let's take a look about order of preference / order of loading. We all know that we can use the
So the order of loading would be:
However... It's not! It's actually:
Like I said, this is due to how the arrays are merged in
So in short: loading a module later on will cause it's added values to appear earlier. This is kind of the opposite what you would expect.
A real world example
Not a big deal you might ask. However, this is a big deal if you're trying to do something where the order of the array matters. For example, I've recently was given the task to add a new renderer to the webapi module (your can read more about it here, and more about my implementation here).
By default, the renderers that the webapi module has are
Now, I've added my own custom renderer to this list (
Now take a look at
If I make an request with
The result? All API-requests that had the
The way I see it this ticket can go in 2 directions:
Perhaps both deserve attention.
Sorry for the long ticket, but I don't know how else I could explain this.
User agents that cannot really handle
The originator of this request (in the example above, the
...but also it would be nice if the merge order were more sane
@kanduvisla, thank you for your report.
We've created internal ticket(s) MAGETWO-85299 to track progress on the issue.