Skip to content

Commit 78937c9

Browse files
committed
Merge branch 'PHP-8.2'
2 parents f45b3ac + a45bef0 commit 78937c9

File tree

6 files changed

+82
-5
lines changed

6 files changed

+82
-5
lines changed

Zend/zend_API.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ typedef struct _zend_fcall_info_cache {
144144
{ #name, ZEND_TYPE_INIT_MASK(type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
145145
#define ZEND_ARG_OBJ_TYPE_MASK(pass_by_ref, name, class_name, type_mask, default_value) \
146146
{ #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
147-
#define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, class_name, type_mask, default_value) \
148-
{ #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
147+
#define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, class_name, type_mask) \
148+
{ #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
149149

150150
/* Arginfo structures with object type information */
151151
#define ZEND_ARG_OBJ_INFO(pass_by_ref, name, class_name, allow_null) \

build/gen_stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3930,10 +3930,10 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string {
39303930
$arginfoType = $argType->toArginfoType();
39313931
if ($arginfoType->hasClassType()) {
39323932
$code .= sprintf(
3933-
"\tZEND_%s_OBJ_TYPE_MASK(%s, %s, %s, %s, %s)\n",
3933+
"\tZEND_%s_OBJ_TYPE_MASK(%s, %s, %s, %s%s)\n",
39343934
$argKind, $argInfo->getSendByString(), $argInfo->name,
39353935
$arginfoType->toClassTypeString(), $arginfoType->toTypeMask(),
3936-
$argInfo->getDefaultValueAsArginfoString()
3936+
!$argInfo->isVariadic ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
39373937
);
39383938
} else {
39393939
$code .= sprintf(

ext/zend_test/test.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,31 @@ static ZEND_METHOD(_ZendTestClass, returnsThrowable)
618618
zend_throw_error(NULL, "Dummy");
619619
}
620620

621+
static ZEND_METHOD(_ZendTestClass, variadicTest) {
622+
int argc, i;
623+
zval *args = NULL;
624+
625+
ZEND_PARSE_PARAMETERS_START(0, -1)
626+
Z_PARAM_VARIADIC('*', args, argc)
627+
ZEND_PARSE_PARAMETERS_END();
628+
629+
for (i = 0; i < argc; i++) {
630+
zval *arg = args + i;
631+
632+
if (Z_TYPE_P(arg) == IS_STRING) {
633+
continue;
634+
}
635+
if (Z_TYPE_P(arg) == IS_OBJECT && instanceof_function(Z_OBJ_P(arg)->ce, zend_ce_iterator)) {
636+
continue;
637+
}
638+
639+
zend_argument_type_error(i + 1, "must be of class Iterator or a string, %s given", zend_zval_type_name(arg));
640+
RETURN_THROWS();
641+
}
642+
643+
object_init_ex(return_value, zend_get_called_scope(execute_data));
644+
}
645+
621646
static ZEND_METHOD(_ZendTestChildClass, returnsThrowable)
622647
{
623648
ZEND_PARSE_PARAMETERS_NONE();

ext/zend_test/test.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public function __toString(): string {}
4343
public function returnsStatic(): static {}
4444

4545
public function returnsThrowable(): Throwable {}
46+
47+
static public function variadicTest(string|Iterator ...$elements) : static {}
4648
}
4749

4850
class _ZendTestChildClass extends _ZendTestClass

ext/zend_test/test_arginfo.h

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
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)