3

Let's say we have a custom PHP extension like:

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

How can I call myfunction() from the RSHUTDOWN handler?

2
  • Did you ever figure this out? I was trying to think of a way to call json_encode from inside a custom ext. function and couldn't figure out how to pull it off. Commented Dec 30, 2010 at 5:41
  • 1
    call_user_func('json_encode', $param); Commented May 29, 2011 at 6:45

2 Answers 2

6

Using the provided macros the call will be:

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

When you're defining you function as PHP_FUNCTION(myFunction) the preprocessor will expand you're definition to:

ZEND_FN(myFunction)(INTERNAL_FUNCTION_PARAMETERS)

which in turn is:

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

The macros from zend.h and 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
Sign up to request clarification or add additional context in comments.

Comments

3

Why dont you make the PHP_FUNCTION a stub like so:

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.