Why does PHP not throw an error when I pass too many parameters to a function?
It is not wrong to pass more arguments to a function than needed.
You only get error if you pass to few arguments.
function test($arg1) {
var_dump($arg1);
}
test();
Above will result in following error:
Uncaught ArgumentCountError: Too few arguments to function...
If you want to fetch first argument plus all others arguments passed to function you can do:
function test($arg1, ...$args) {
var_dump($arg1, $args);
}
test('test1', 'test2', 'test3');
Resulting in:
string(5) "test1"
array(2) {
[0]=>
string(5) "test2"
[1]=>
string(5) "test3"
}
PHP doesn't throw an error on function overload.