忽然笑
写PHP扩展最好的参考资料是官方代码库,即便不算best practice,也不至于太差。先下载一份php源码,然后在ext目录里搜 call_user_function,把参数个数>=2的列出来。比如 ext/readline/readline.cstatic char **_readline_completion_cb(const char *text, int start, int end){zval params[3];int i;char **matches = NULL;_readline_string_zval(¶ms[0], text);_readline_long_zval(¶ms[1], start);_readline_long_zval(¶ms[2], end);if (call_user_function(CG(function_table), NULL, &_readline_completion, &_readline_array, 3, params) == SUCCESS) {if (Z_TYPE(_readline_array) == IS_ARRAY) {if (zend_hash_num_elements(Z_ARRVAL(_readline_array))) {matches = rl_completion_matches(text,_readline_command_generator);} else {matches = malloc(sizeof(char *) * 2);if (!matches) {return NULL;}matches[0] = strdup("");matches[1] = '\0';}}}for (i = 0; i < 3; i++) {zval_ptr_dtor(¶ms[i]);}zval_ptr_dtor(&_readline_array);return matches;}看一下call_user_function的签名,它参数是个数组,zval params[]ZEND_API int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation);#define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \_call_user_function_ex(object, function_name, retval_ptr, param_count, params, 1)#define call_user_function_ex(function_table, object, function_name, retval_ptr, param_count, params, no_separation, symbol_table) \_call_user_function_ex(object, function_name, retval_ptr, param_count, params, no_separation)