@@ -31,28 +31,38 @@ resources cannot be auto-converted.
3131
3232Type specifiers
3333---------------
34- a - array
35- b - boolean, stored in zend_bool
36- d - double
37- f - function or array containing php method call info (returned as
38- zend_fcall_info* and zend_fcall_info_cache*)
39- h - array (returned as HashTable*)
40- l - long
41- o - object (of any type)
42- O - object (of specific type, specified by class entry)
43- r - resource (stored in zval)
44- s - string (with possible null bytes) and its length
45- z - the actual zval
34+ The following list shows the type specifier, its meaning and the parameter
35+ types that need to be passed by address. All passed paramaters are set
36+ if the PHP parameter is non optional and untouched if optional and the
37+ parameter is not present. The only exception is O where the zend_class_entry*
38+ has to be provided on input and is used to verify the PHP parameter is an
39+ instance of that class.
40+
41+ a - array (zval*)
42+ b - boolean (zend_bool)
43+ C - class (zend_class_entry*)
44+ d - double (double)
45+ f - function or array containing php method call info (returned as
46+ zend_fcall_info and zend_fcall_info_cache)
47+ h - array (returned as HashTable*)
48+ l - long (long)
49+ o - object of any type (zval*)
50+ O - object of specific type given by class entry (zval*, zend_class_entry)
51+ r - resource (zval*)
52+ s - string (with possible null bytes) and its length (char*, int)
53+ z - the actual zval (zval*)
54+ Z - the actual zval (zval**)
55+ * - variable arguments list
4656
4757 The following characters also have a meaning in the specifier string:
48- | - indicates that the remaining parameters are optional, they
49- should be initialized to default values by the extension since they
50- will not be touched by the parsing function if they are not
51- passed to it.
52- / - use SEPARATE_ZVAL_IF_NOT_REF() on the parameter it follows
53- ! - the parameter it follows can be of specified type or NULL (only applies
54- to 's', 'a', 'o', 'O', 'r ', 'h ', 'C', 'z', and 'Z '). If NULL is passed,
55- the results pointer is set to NULL as well.
58+ | - indicates that the remaining parameters are optional, they
59+ should be initialized to default values by the extension since they
60+ will not be touched by the parsing function if they are not
61+ passed to it.
62+ / - use SEPARATE_ZVAL_IF_NOT_REF() on the parameter it follows
63+ ! - the parameter it follows can be of specified type or NULL (applies
64+ to all specifiers except for 'b ', 'l ', and 'd '). If NULL is passed, the
65+ results pointer is set to NULL as well.
5666
5767Examples
5868--------
@@ -62,8 +72,8 @@ char *s;
6272int s_len;
6373zval *param;
6474if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsz",
65- &l, &s, &s_len, ¶m) == FAILURE) {
66- return;
75+ &l, &s, &s_len, ¶m) == FAILURE) {
76+ return;
6777}
6878
6979
@@ -72,8 +82,8 @@ zval *obj;
7282double d = 0.5;
7383zend_class_entry *my_ce;
7484if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|d",
75- &obj, my_ce, &d) == FAILURE) {
76- return;
85+ &obj, my_ce, &d) == FAILURE) {
86+ return;
7787}
7888
7989
@@ -82,29 +92,18 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|d",
8292zval *obj;
8393zval *arr;
8494if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o!a",
85- &obj, &arr) == FAILURE) {
86- return;
95+ &obj, &arr) == FAILURE) {
96+ return;
8797}
8898
8999
90100/* Gets a separated array which can also be null. */
91101zval *arr;
92102if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!",
93- &arr) == FAILURE) {
94- return;
103+ &arr) == FAILURE) {
104+ return;
95105}
96106
97-
98- /* Get only the first three parameters (useful for varargs functions). */
99- zval *z;
100- zend_bool b;
101- zval *r;
102- if (zend_parse_parameters(3 TSRMLS_CC, "zbr!",
103- &z, &b, &r) == FAILURE) {
104- return;
105- }
106-
107-
108107/* Get either a set of 3 longs or a string. */
109108long l1, l2, l3;
110109char *s;
@@ -118,13 +117,72 @@ char *s;
118117int length;
119118
120119if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
121- "lll", &l1, &l2, &l3) == SUCCESS) {
122- /* manipulate longs */
120+ "lll", &l1, &l2, &l3) == SUCCESS) {
121+ /* manipulate longs */
123122} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
124- "s", &s, &length) == SUCCESS) {
125- /* manipulate string */
123+ "s", &s, &length) == SUCCESS) {
124+ /* manipulate string */
126125} else {
127- /* output error */
126+ /* output error */
127+
128+ return;
129+ }
130+
131+
132+ /* Function that accepts only varargs (0 or more) */
133+
134+ int i, num_varargs;
135+ zval ***varargs = NULL;
136+
137+
138+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", &varargs, &num_varargs) == FAILURE) {
139+ return;
140+ }
141+
142+ for (i = 0; i < num_varargs; i++) {
143+ /* do something with varargs[i] */
144+ }
145+
146+ if (varargs) {
147+ efree(varargs);
148+ }
128149
129- return;
150+
151+ /* Function that accepts a string, followed by varargs (1 or more) */
152+
153+ char *str;
154+ int str_len;
155+ int i, num_varargs;
156+ zval ***varargs = NULL;
157+
158+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s+", &str, &str_len, &varargs, &num_varargs) == FAILURE) {
159+ return;
160+ }
161+
162+ for (i = 0; i < num_varargs; i++) {
163+ /* do something with varargs[i] */
164+ }
165+
166+ if (varargs) {
167+ efree(varargs);
168+ }
169+
170+
171+ /* Function that takes an array, followed by varargs, and ending with a long */
172+ long num;
173+ zval *array;
174+ int i, num_varargs;
175+ zval ***varargs = NULL;
176+
177+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a*l", &array, &varargs, &num_varargs, &num) == FAILURE) {
178+ return;
179+ }
180+
181+ for (i = 0; i < num_varargs; i++) {
182+ /* do something with varargs[i] */
183+ }
184+
185+ if (varargs) {
186+ efree(varargs);
130187}
188+
0 commit comments