class foo
{
public function bar()
{
echo 'This is a test';
}
}
$callback = [new foo, 'bar'];
$callback(); // It echoes "This is a test"
Steps To Reproduce:
In the routes file:
class foo {
public function bar() {
echo 'This is a test';
}
}
Route::get(
'/test',
[new foo, 'bar']
);
This throws an error in Illuminate\Routing\RouteAction as in line 34 it tries to convert the object to a string when concatenating for uses and controller in return array.
I opened this issue: https://github.com/laravel/framework/issues/36079
It is not supported, adding support would be perfect as it's essential for some programming paradigms.
Description:
In the routing, you cannot pass a callable array formed by an object and a string (function name), even this is a supported callable.
PHP manual: https://www.php.net/manual/en/language.types.callable.php (type 3)
You can try it like this:
Steps To Reproduce:
In the routes file:
This throws an error in
Illuminate\Routing\RouteAction
as in line34
it tries to convert the object to a string when concatenating foruses
andcontroller
in return array.