Skip to content

Commit f8891f2

Browse files
committed
Fixed strict zpp arginfo test
1 parent 8a9b80c commit f8891f2

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

ext/zend_test/test.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,25 @@ static ZEND_METHOD(_ZendTestClass, returnsThrowable)
413413
}
414414

415415
static ZEND_METHOD(_ZendTestClass, variadicTest) {
416-
int argc;
416+
int argc, i;
417417
zval *args = NULL;
418418

419419
ZEND_PARSE_PARAMETERS_START(0, -1)
420420
Z_PARAM_VARIADIC('*', args, argc)
421421
ZEND_PARSE_PARAMETERS_END();
422422

423-
(void) (args + argc);
423+
for (i = 0; i < argc; i++) {
424+
zval *arg = args + i;
425+
426+
if (Z_TYPE_P(arg) == IS_STRING) {
427+
continue;
428+
}
429+
if (Z_TYPE_P(arg) == IS_OBJECT && instanceof_function(Z_OBJ_P(arg)->ce, zend_ce_iterator)) {
430+
continue;
431+
}
432+
433+
zend_argument_type_error(i + 1, "must be of class Iterator or a string, %s given", zend_zval_type_name(arg));
434+
}
424435

425436
object_init_ex(return_value, zend_get_called_scope(execute_data));
426437
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Verify that variadic arguments create proper stub
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
$reflection = new ReflectionMethod("_ZendTestClass", "variadicTest");
9+
$arguments = $reflection->getParameters();
10+
11+
echo (string) $arguments[0], "\n";
12+
var_dump($arguments[0]->isVariadic());
13+
14+
$type = $arguments[0]->getType();
15+
16+
var_dump($type instanceof ReflectionUnionType);
17+
18+
echo "\n";
19+
20+
$types = $type->getTypes();
21+
22+
var_dump($types[0]->getName());
23+
var_dump($types[0] instanceof ReflectionNamedType);
24+
var_dump($types[0]->allowsNull());
25+
26+
echo "\n";
27+
28+
var_dump($types[1]->getName());
29+
var_dump($types[1] instanceof ReflectionNamedType);
30+
var_dump($types[1]->allowsNull());
31+
32+
?>
33+
--EXPECTF--
34+
Parameter #0 [ <optional> Iterator|string ...$elements ]
35+
bool(true)
36+
bool(true)
37+
38+
string(8) "Iterator"
39+
bool(true)
40+
bool(false)
41+
42+
string(6) "string"
43+
bool(true)
44+
bool(false)

0 commit comments

Comments
 (0)