gpt4 book ai didi

PHP 扩展 - 从另一个 PHP 函数调用您自己的 PHP 函数

转载 作者:可可西里 更新时间:2023-11-01 00:26:57 26 4
gpt4 key购买 nike

假设我们有一个自定义的 PHP 扩展,例如:

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

如何从 RSHUTDOWN 处理程序调用 myfunction()?

最佳答案

使用提供的宏调用将是:

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

关于PHP 扩展 - 从另一个 PHP 函数调用您自己的 PHP 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4346562/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com