亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP的擴展中回調PHP的函數有多參數的問題?

PHP的擴展中回調PHP的函數有多參數的問題?

PHP
慕姐4208626 2018-11-21 22:18:37
PHP的擴展中回調PHP的函數有多參數的問題
查看完整描述

1 回答

?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

寫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)

查看完整回答
反對 回復 2018-12-14
  • 1 回答
  • 0 關注
  • 554 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號