2010-12-03 71 views
2

調用自己的PHP函數比方說,我們有一個自定義PHP擴展,如:PHP擴展 - 從另一個PHP函數

PHP_RSHUTDOWN_FUNCTION(myextension) 
{ 
    // How do I call myfunction() from here? 
    return SUCCESS; 
} 
PHP_FUNCTION(myfunction) 
{ 
    // Do something here 
    ... 
    RETURN_NULL; 
} 

我如何可以調用從RSHUTDOWN處理器MyFunction的()?

+0

你想要執行? – 2010-12-03 14:54:21

回答

5

使用所提供的宏調用將是:

PHP_RSHUTDOWN_FUNCTION(myextension) 
{ 
    ZEND_FN(myFunction)(0, NULL, NULL, NULL, 0 TSRMLS_CC); 
    return SUCCESS; 
} 

當你確定你作爲PHP_FUNCTION(myFunction)預處理程序展開你的定義爲:

ZEND_FN(myFunction)(INTERNAL_FUNCTION_PARAMETERS) 

然後是:

zif_myFunction(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC) 

從zend.h和php.h的宏:

#define PHP_FUNCTION   ZEND_FUNCTION 
#define ZEND_FUNCTION(name)   ZEND_NAMED_FUNCTION(ZEND_FN(name)) 
#define ZEND_FN(name)      zif_##name 
#define ZEND_NAMED_FUNCTION(name)  void name(INTERNAL_FUNCTION_PARAMETERS) 
#define INTERNAL_FUNCTION_PARAMETERS int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC 
#define INTERNAL_FUNCTION_PARAM_PASSTHRU ht, return_value, return_value_ptr, this_ptr, return_value_used TSRMLS_CC 
2

你爲什麼不使PHP_FUNCTION存根像這樣:

void doStuff() 
{ 
    // Do something here 
    ... 
} 

PHP_RSHUTDOWN_FUNCTION(myextension) 
{ 
    doStuff(); 
    return SUCCESS; 
} 
PHP_FUNCTION(myfunction) 
{ 
    doStuff(); 
    RETURN_NULL; 
}