let me elaborate more on the Title. Consider for example PHP_FUNCTION(session_start). Will I be able to invoke session_start from within session_id which is another PHP_FUNCTION (this is just for illustration not the actual purpose)?
let me elaborate more on the Title. Consider for example PHP_FUNCTION(session_start). Will I be
Share
Well, yes, but you should avoid it as much as possible. One of the main benefits of writing internal implementations of functions is that, contrary to what happens in PHP, C function calls are cheap. Additionally, calling PHP functions internally in C code is relatively painful.
For instance, in the case of
session_start, you havephp_session_start, which is exposed by the session extension. Owing to what I described in the first paragraph, extensions will usually export C functions that may be useful to others.In fact, the internal PHP function
fooneeded to call the internal PHP functionbar, the best strategy, if possible, would be to define an auxiliary (nonPHP_FUNCTION) C function with most of the implementation ofbar. Then bothPHP_FUNCTION(foo)andPHP_FUNCTION(bar)could call that auxiliary function.Anyway, the easiest way to call PHP functions is to use
call_user_function:The variant
call_user_function_exalso allows prohibiting separation when the argument should be sent by reference by it’s not and specifying a symbol table.This will work both if the relevant function is internal (
PHP_FUNCTION) or was defined in userspace. If it’s a regular function, you should useEG(function_table)as the first argument, the second should be NULL and I think you can figure out the others.If you execute the function several times, this is not very efficient. In that case, see the functions in “Zend_API.h” that start with
zend_fcall_.I wouldn’t recommend other options to call internal functions, such as manually setting up the arguments stack and other trickery and them manually calling the underlying C function.