Jun 20

在PHP的扩展(extension)中调用其他的php函数 不指定

felix021 @ 2011-6-20 15:28 [IT » 程序设计] 评论(0) , 引用(0) , 阅读(7155) | Via 本站原创 | |
=> How to call a php function in a php extension

详细的说明参见:

[php-5.2.17]
    /Zend/zend_execute_API.c +623 & +636    call_user_function_ex
    /ext/standard/basic_functions.c +5174    PHP_FUNCTION(call_user_func_array)                                                                       
    /ext/pcre/pcre.c +833  (in function "preg_do_repl_func")

http://man.chinaunix.net/develop/php/php_manual_zh/html/zend.calling-user-functions.html

http://www.phpfreaks.com/forums/index.php?topic=10272.0

PHP_FUNCTION (caller)
{
    //call_user_function_ex
    zval *function, *str, *arr;
    zval **params[10];

    MAKE_STD_ZVAL(function);
    ZVAL_STRING(function, "var_dump", 1);  //I wanna call var_dump

    /*  //pass a string as its param
    MAKE_STD_ZVAL(str);
    ZVAL_STRING(str, "Hello, world!", 1);

    params[0] = &str;
    */

    //pass an array as its param
    MAKE_STD_ZVAL(arr);
    array_init(arr);
    add_assoc_string(arr, "name", "felix021", 1);
    params[0] = &arr;

    zval *ret;
    if (call_user_function_ex(CG(function_table), NULL,
            function, &ret, 2, params, 0, NULL TSRMLS_CC) != FAILURE)
    {
        *return_value = *ret;
        zval_copy_ctor(return_value);
        zval_ptr_dtor(&ret);
        return;
    }
    else {
        RETURN_FALSE;
    }
}





欢迎扫码关注:




转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   *非必须
网址   电邮   [注册]