I have a PHP library function expecting a callback with no arguments.
I know I can pass an object's method with array($this , 'my_function_name')
but how can I give parameters to the my_function_name
?
I have found a solution using create_function
but from PHP manual I see it has security issues.
$that = $this;
$wrapper = function() use($that) {
return $that->my_function_name('arg1', 'arg2');
};
There is a function called call_user_func_array.
call_user_func_array([$this, 'method'], $args);
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