Closed
Description
- Laravel Version: 5.5
- PHP Version: 7.1
- Database Driver & Version: MySQL 5.7 / PDO
Description:
BoundMethod::call() will send parameters to the function in wrong order in some cases. If a function parameter has a default value set and one precedes it with no default value, the default value from the second parameter will be applied to the first parameter.
Steps To Reproduce:
//... some class ...
public function list(string $url, string $type = 'all'): void
{
var_dump($url);
var_dump($type);
}
//... some container ...
$this->app->call("SomeClass@list", ['testparam']);
This will result in output:
string 'all' (length=3)
string 'testparam' (length=24)
So the default value for $type was sent to $url parameter instead.
Explanation:
This is because in BoundMethod on line 119
return array_merge($dependencies, $parameters);
the results from depedency resolution are merged with no order at all. The dependencies are resolved first and after that the parameters so no order is taken into account.
How to fix:
In function addDepdencyForCallParameter take given parameters into account and fill dependecies in such a way that the order is preserved.
Metadata
Metadata
Assignees
Labels
No labels