Question

I'm writing small php extension and have problem when building it. The code:

PHP_RINIT_FUNCTION(pstat)
{
    int argc = ZEND_NUM_ARGS();
    return SUCCESS;
}

on make got an error:

.... /ext/pstat/pstat.c:122:31: error: 'ht' undeclared (first use in this function)

ZEND_NUM_ARGS() is a macros in Zend_API.h

#define ZEND_NUM_ARGS()     (ht)

but what is 'ht'? Any ideas?

Was it helpful?

Solution

Why are you using ZEND_NUM_ARGS() here? This is the request initialisation function, and will not be receiving any user supplied arguments.


Typically but not always, ht is used to denote a hash table.

ZEND_NUM_ARGS() is usually used within a function defined with the PHP_FUNCTION macro, to get the number of arguments passed to an internal function from a PHP script.


If you trace back from the PHP_FUNCTION macro you'll end up seeing the following standard set of arguments used in an internal function definition.

#define INTERNAL_FUNCTION_PARAMETERS int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC

As you can see, this definition includes ht as an int.

The arguments for PHP_RINIT_FUNCTION do not include ht.

#define INIT_FUNC_ARGS      int type, int module_number TSRMLS_DC
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top