Skip to content

Commit a541bb8

Browse files
author
Jani Taskinen
committed
- Fix tests
- Update README.PARAMETER_PARSING_API
1 parent b489251 commit a541bb8

170 files changed

Lines changed: 4995 additions & 2506 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.PARAMETER_PARSING_API

Lines changed: 103 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,38 @@ resources cannot be auto-converted.
3131

3232
Type 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

5767
Examples
5868
--------
@@ -62,8 +72,8 @@ char *s;
6272
int s_len;
6373
zval *param;
6474
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsz",
65-
&l, &s, &s_len, &param) == FAILURE) {
66-
return;
75+
&l, &s, &s_len, &param) == FAILURE) {
76+
return;
6777
}
6878

6979

@@ -72,8 +82,8 @@ zval *obj;
7282
double d = 0.5;
7383
zend_class_entry *my_ce;
7484
if (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",
8292
zval *obj;
8393
zval *arr;
8494
if (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. */
91101
zval *arr;
92102
if (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. */
109108
long l1, l2, l3;
110109
char *s;
@@ -118,13 +117,72 @@ char *s;
118117
int length;
119118

120119
if (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+

Zend/tests/bug31720.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ array_walk($array, array($nonesuchvar,'show'));
1010
--EXPECTF--
1111
Notice: Undefined variable: nonesuchvar in %s on line %d
1212

13-
Notice: Non-callable array passed to zend_call_function() in %s on line %d
14-
15-
Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d
13+
Warning: array_walk() expects parameter 2 to be valid callback, array given in %s on line %d
1614
===DONE===

Zend/tests/bug32290.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Bug #32290 (calling call_user_func_array() ends in infinite loop within child class)
3+
--INI--
4+
error_reporting=8191
35
--FILE--
46
<?php
57

@@ -98,9 +100,8 @@ var_dump($x->doSomethingStatic(1));
98100
===A===
99101
TestB::doSomething(1)
100102

101-
Strict Standards: Non-static method TestA::doSomething() cannot be called statically, assuming $this from compatible context TestB in %sbug32290.php on line %d
102-
TestA::doSomething(2)
103-
int(1)
103+
Warning: call_user_func_array() expects parameter 1 to be valid callback, array given in %s on line %d
104+
NULL
104105

105106
===B===
106107
TestB::doSomethingThis(1)
@@ -110,9 +111,8 @@ int(1)
110111
===C===
111112
TestB::doSomethingParent(1)
112113

113-
Strict Standards: Non-static method TestA::doSomethingParent() cannot be called statically, assuming $this from compatible context TestB in %sbug32290.php on line %d
114-
TestA::doSomethingParent(2)
115-
int(1)
114+
Warning: call_user_func_array() expects parameter 1 to be valid callback, array given in %s on line %d
115+
NULL
116116

117117
===D===
118118
TestB::doSomethingParentThis(1)

Zend/tests/bug36214.phpt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ $ctx->comment_preview[0] = 1;
3333
$ctx->comment_preview[1] = 2;
3434
var_dump($ctx->comment_preview);
3535
?>
36-
--EXPECT--
36+
--EXPECTF--
3737
array(2) {
3838
[0]=>
3939
int(1)
@@ -46,9 +46,12 @@ array(2) {
4646
[1]=>
4747
int(2)
4848
}
49-
object(ArrayObject)#2 (2) {
50-
[0]=>
51-
int(1)
52-
[1]=>
53-
int(2)
49+
object(ArrayObject)#%d (1) {
50+
["storage":"ArrayObject":private]=>
51+
array(2) {
52+
[0]=>
53+
int(1)
54+
[1]=>
55+
int(2)
56+
}
5457
}

Zend/tests/bug37212.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ var_dump($B);
4141
===DONE===
4242
--EXPECTF--
4343
object(B)#%d (1) {
44-
["value:protected"]=>
44+
["value":protected]=>
4545
string(1) "B"
4646
}
4747
object(C)#%d (1) {
48-
["value:protected"]=>
48+
["value":protected]=>
4949
string(1) "C"
5050
}
5151
object(B)#%d (1) {
52-
["value:protected"]=>
52+
["value":protected]=>
5353
string(1) "C"
5454
}
5555
===DONE===

Zend/tests/bug37667.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ string(3) "bar"
3333
Notice: Undefined offset: 2 in %sbug37667.php on line 16
3434
NULL
3535
object(Test)#%d (1) {
36-
["property:protected"]=>
36+
["property":protected]=>
3737
array(1) {
3838
["foo"]=>
3939
string(3) "bar"
@@ -44,7 +44,7 @@ Notice: Indirect modification of overloaded property Test::$property has no effe
4444

4545
Notice: Indirect modification of overloaded property Test::$property has no effect in %sbug37667.php on line 21
4646
object(Test)#%d (1) {
47-
["property:protected"]=>
47+
["property":protected]=>
4848
array(1) {
4949
["foo"]=>
5050
string(3) "bar"

ext/dom/tests/dom003.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ $rootNode->appendChild($rootNode);
2222
--EXPECTF--
2323
--- Catch exception with try/catch
2424
object(DOMException)#%d (6) {
25-
["message:protected"]=>
25+
["message":protected]=>
2626
string(23) "Hierarchy Request Error"
27-
["string:private"]=>
27+
["string":"Exception":private]=>
2828
string(0) ""
29-
["file:protected"]=>
29+
["file":protected]=>
3030
string(%d) "%sdom003.php"
31-
["line:protected"]=>
31+
["line":protected]=>
3232
int(8)
33-
["trace:private"]=>
33+
["trace":"Exception":private]=>
3434
array(1) {
3535
[0]=>
3636
array(6) {

ext/dom/tests/dom_set_attr_node.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ try {
3232
?>
3333
--EXPECTF--
3434
object(DOMException)#%d (6) {
35-
["message:protected"]=>
35+
["message":protected]=>
3636
string(20) "Wrong Document Error"
37-
["string:private"]=>
37+
["string":"Exception":private]=>
3838
string(0) ""
39-
["file:protected"]=>
39+
["file":protected]=>
4040
string(%d) "%sdom_set_attr_node.php"
41-
["line:protected"]=>
41+
["line":protected]=>
4242
int(%d)
43-
["trace:private"]=>
43+
["trace":"Exception":private]=>
4444
array(1) {
4545
[0]=>
4646
array(6) {

0 commit comments

Comments
 (0)