Skip to content

app()->call() has a problem calling class methods with default parameter values #26851

Closed
@imanghafoori1

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:

  1. 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");
    }
}
  1. 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'] );
});
  1. 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

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