'Cannot use positional argument after named argument in PHP
<?php
use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AdminPanel\HomeController as AdminHomeController;
Route::post(uri:'save',[HomeController::class,'save']);
Route::get(uri:'/admin',[AdminHomeController::class, 'index']);
Why can't i use this parameters ? Why am i getting this error i have no idea.
Solution 1:[1]
Good old-fashioned positional parameters are identified by, well, their position. On the other side, named parameters can be shuffled because its their name what defines what they are:
function foo($a, $b) {
var_dump($a, $b);
}
foo(10, 20);
foo(b: 20, a: 10);
Both calls print the same result:
int(10)
int(20)
However, if you mix them, there's no way to reliably determine what parameters you mean:
foo(b: 20, 10); // Is 10 the second parameter ($b)?
Yes, PHP could have implemented complex rules to resolve any ambiguity, but that would be unlikely to enhance code readability.
So... you need to pick one: named or positional.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ãlvaro González |
