PHP. Extension. Call existing PHP function

随声附和 提交于 2019-12-02 19:10:43

The easiest way to figure out how a function works is to search for it on lxr.php.net. The first example that turns up is in readline: http://lxr.php.net/xref/PHP_TRUNK/ext/readline/readline.c#474

The use for mail is analogous. Given the arguments as zvals (to_zval, from_zval, msg_zval) the call is very simple:

zval *params = { to_zval, from_zval, msg_zval };
zend_uint param_count = 3;
zval *retval_ptr;

zval function_name;
INIT_ZVAL(function_name);
ZVAL_STRING(&function_name, "mail", 1);

if (call_user_function(
        CG(function_table), NULL /* no object */, &function_name,
        retval_ptr, param_count, params TSRMLS_CC
    ) == SUCCESS
) {
    /* do something with retval_ptr here if you like */
}

/* don't forget to free the zvals */
zval_ptr_dtor(&retval_ptr);
zval_dtor(&function_name);

If you don't have the parameters as zvals already, then you can create them using MAKE_STD_ZVAL and ZVAL_STRING.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!