Old way of retrieving arguments (deprecated)
Deprecated parameter parsing API:
This API is deprecated and superseded by the new ZEND
parameter parsing API_
After having checked the number of arguments, you need to get access
to the arguments themselves_ This is done with the help of
zend_get_parameters_ex():
zval **parameter;
if(zend_get_parameters_ex(1, ¶meter) != SUCCESS)
WRONG_PARAM_COUNT; |
All arguments are stored in a
zval container,
which needs to be pointed to
twice_ The snippet above
tries to retrieve one argument and make it available to us via the
parameter pointer_
zend_get_parameters_ex() accepts at least two
arguments_ The first argument is the number of arguments to
retrieve (which should match the number of arguments with which
the function has been called; this is why it's important to check
for correct call syntax)_ The second argument (and all following
arguments) are pointers to pointers to pointers to
zvals_ (Confusing, isn't it?) All these pointers
are required because Zend works internally with
**zval; to adjust a local **zval in
our function,zend_get_parameters_ex() requires
a pointer to it_
The return value of zend_get_parameters_ex()
can either be SUCCESS or
FAILURE, indicating (unsurprisingly) success or
failure of the argument processing_ A failure is most likely
related to an incorrect number of arguments being specified, in
which case you should exit with
WRONG_PARAM_COUNT_
To retrieve more than one argument, you can use a similar snippet:
zval **param1, **param2, **param3, **param4;
if(zend_get_parameters_ex(4, ¶m1, ¶m2, ¶m3, ¶m4) != SUCCESS)
WRONG_PARAM_COUNT; |
zend_get_parameters_ex() only checks whether
you're trying to retrieve too many parameters_ If the function is
called with five arguments, but you're only retrieving three of
them with zend_get_parameters_ex(), you won't
get an error but will get the first three parameters instead_
Subsequent calls of zend_get_parameters_ex()
won't retrieve the remaining arguments, but will get the same
arguments again_