I'm making a controller, which calls a different method from a class and I want to make it as generic as possible. I currently have this code:
//More code up, just showing the important code part
$geo = new Geolocation();
$res = $geo->{$method}(...$params);
echo json_encode($res);
What I want is pass an array as arguments to my Geolocation class.
I took an idea from the next thread: Passing an Array as Arguments, not an Array, in PHP
The problem is that "splat operator" ... is not working for me, probably because it's not a function. Is there any related solution?
PHP 5.6.20
The first answer for the question you link shows call_user_func_array(), so with an object method do:
$res = call_user_func_array(array($geo, $method), $params);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With