m1t*_*tk4 3 php c php-extension
假设我们有一个自定义PHP扩展,如:
PHP_RSHUTDOWN_FUNCTION(myextension)
{
// How do I call myfunction() from here?
return SUCCESS;
}
PHP_FUNCTION(myfunction)
{
// Do something here
...
RETURN_NULL;
}
Run Code Online (Sandbox Code Playgroud)
如何从RSHUTDOWN处理程序调用myfunction()?
使用提供的宏,调用将是:
PHP_RSHUTDOWN_FUNCTION(myextension)
{
ZEND_FN(myFunction)(0, NULL, NULL, NULL, 0 TSRMLS_CC);
return SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
当您定义功能时,PHP_FUNCTION(myFunction)预处理器将扩展您的定义为:
ZEND_FN(myFunction)(INTERNAL_FUNCTION_PARAMETERS)
Run Code Online (Sandbox Code Playgroud)
反过来又是:
zif_myFunction(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC)
Run Code Online (Sandbox Code Playgroud)
来自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
Run Code Online (Sandbox Code Playgroud)