Is it possible? Without using Zend API, only Native. For use it like in PHP extension:
call_user_function(EG(function_table), NULL, &func, &retval, 1, params);
Is it possible? Without using Zend API, only Native. For use it like in PHP extension:
call_user_function(EG(function_table), NULL, &func, &retval, 1, params);
You most likely want vm_call_user_func().
Variant vm_call_user_func(const Variant& function, const Variant& params,
bool forwarding = false);
Depending on what your extension is doing at the time of the call, you likely will want to catch exceptions the function may throw.
try {
vm_call_user_func(function, params);
} catch (const Object&) {
try {
raise_warning("got exception in my extension");
} catch (const Object&) {
// exception in error handler!
}
}
vm_call_user_func
knows how to handle the various ways PHP defines callables (e.g. "SomeClass::someMethod"
, array($obj, "method")
).
Depending on how the function to call is being provided, there may be more optimal ways. You could require that instead of any arbitrary callback, the user must provide a closure object. Since a closure object is always callable (i.e. you don't have to validate that SomeClass
exists in my "SomeClass::someMethod"
example), you can extract the underlying object, store it instead of the Variant
and vm_call_user_func()
will save some overhead decoding and validating it.