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)?
2条回答 默认 最新
- doqdcks3948 2010-09-01 03:53关注
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
foo
needed 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
:int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zend_uint param_count, zval *params[] TSRMLS_DC);
The variant
call_user_function_ex
also 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.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 乌班图ip地址配置及远程SSH
- ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
- ¥15 PSPICE制作一个加法器
- ¥15 javaweb项目无法正常跳转
- ¥15 VMBox虚拟机无法访问
- ¥15 skd显示找不到头文件
- ¥15 机器视觉中图片中长度与真实长度的关系
- ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
- ¥15 java 的protected权限 ,问题在注释里
- ¥15 这个是哪里有问题啊?