app()->call() has a problem calling class methods with default parameter values #26851
Closed
Description
- Laravel Version: 5.7.14
- PHP Version: 7.2.9
Description:
app()->call() has a problem calling class methods with default parameter values.
Steps To Reproduce:
- A fresh installation of laravel.
2 . define a simple class in app folder
namespace App;
class Foo
{
function bar($a, $b, $c = 'my C')
{
dd("a : $a", "b : $b", "c : $c");
}
function baz($a = 'my A', $b = 'my B' , $c = 'my C')
{
dd("a : $a", "b : $b", "c : $c");
}
}
- define a route in web.php
Route::get('/bar', function () {
app()->call('\App\Foo@bar', ['a', 'b'] );
});
Route::get('/baz', function () {
app()->call('\App\Foo@baz', ['a', 'b', 'c'] );
});
- php artisan serve, then visit '/bar' and '/baz' in the browser, you will get totally unexpected results.
Note that this feature is documented in the docblocks like this:
Call the given Closure / class@method and inject its dependencies.
vendor/laravel/framework/src/Illuminate/Container/Container.php
line 563
I have created the PR to fix this bug. and it is very easy to fix.
Metadata
Assignees
Labels
No labels