PHP擴展裏經過 call_user_function_ex 調用用戶空間函數

最近在看YAF的源碼,其中可能我認爲最關鍵的應該是在PHP擴展裏怎麼調用用戶空間裏的函數了!對於一個framework來講,最基本的功能就是路由到請求對應的Action了。 php

在PHP擴展裏是經過 call_user_function_ex 函數來調用用戶空間的函數的。下面咱們來分析下這個函數的使用方式吧。 函數

下面這個是call_user_function_ex 函數的定義: post

ZEND_API int call_user_function_ex(
	HashTable *function_table, 
	zval **object_pp, 
	zval *function_name, 
	zval **retval_ptr_ptr, 
	zend_uint param_count, 
	zval **params[], 
	int no_seperation, 
	HashTable *symbol_table TSRMLS_DC);

function_table is the hash table where the function you wish to call is located. If you\'re using object_pp, set this to NULL. If the function is global, most likely it\'s located in the hash table returned by the macro CG() with the parameter `function_table\', i.e. ui

CG(function_table)
object_pp is a pointer to a zval pointer where an initialized object is located. If you use this, set function_table to NULL, as previously noted.
function_name is a pointer to a zval which contains the name of the function in string form.
retval_ptr_ptr is a pointer to a zval pointer which will contain the return value of the function. The zval passed doesn\'t need to be initialized, and it may cause problems if you initialize it when it\'s not neccesary. You  must  always pass a real pointer to a zval pointer, you may not use NULL for this as it will cause a segmentation fault.
param_count is the number of parameters you wish to pass to the function being called.
params is an array of pointers to zval pointers. Note: this is _not_ a PHP/zval array, it is a C array. Example:
zval *foo; zval *bar; zval **params[2]; params[0] = &foo; params[1] = bar;
no_seperation is either 1 or 0, 0 being no zval seperation, 1 enabling zval seperation. 
symbol_table is the hash table for symbols. I currently don\'t know what this is, so when I find out, I\'ll edit the post and put it here
After the symbol_table parameter, you should put TSRMLS_CC to make it threadsafe.

http://forums.phpfreaks.com/topic/1303-call-user-function-ex-documentation/ this



相關文章
相關標籤/搜索