If I have the following class:
class MyClass
{
public function hello($name)
{
echo 'Hello ' . $name;
}
}
If I use the following code to call the function (the name of the function and parameters are determined based on user input):
$className = 'MyClass';
$func = 'hello';
$params = ['John', 'Another Param'];
$myClass = new $className();
$myClass->$func(...$params);
The function is called and the extra parameter is ignored. What I would like to do, is ensure that the number of parameters in $params matches that of the function and have and throw an ArgumentCountError if the number of arguments do not match.
I have been searching but have not found any solutions. How may I achieve this?