Skip to content

Commit b371843

Browse files
committed
Annotate internal functions with the mixed type
Closes GH-5618
1 parent cbf86ef commit b371843

23 files changed

+181
-273
lines changed

Zend/zend_builtin_functions.stub.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ function zend_version(): string {}
66

77
function func_num_args(): int {}
88

9-
/** @return mixed */
10-
function func_get_arg(int $arg_num) {}
9+
function func_get_arg(int $arg_num): mixed {}
1110

1211
function func_get_args(): array {}
1312

@@ -69,12 +68,12 @@ function trigger_error(string $message, int $error_type = E_USER_NOTICE): bool {
6968
/** @alias trigger_error */
7069
function user_error(string $message, int $error_type = E_USER_NOTICE): bool {}
7170

72-
/** @return mixed */
71+
/** @return string|array|object|null */
7372
function set_error_handler($error_handler, int $error_types = E_ALL) {}
7473

7574
function restore_error_handler(): bool {}
7675

77-
/** @return mixed */
76+
/** @return string|array|object|null */
7877
function set_exception_handler($exception_handler) {}
7978

8079
function restore_exception_handler(): bool {}

Zend/zend_builtin_functions_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ZEND_END_ARG_INFO()
66
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_func_num_args, 0, 0, IS_LONG, 0)
77
ZEND_END_ARG_INFO()
88

9-
ZEND_BEGIN_ARG_INFO_EX(arginfo_func_get_arg, 0, 0, 1)
9+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_func_get_arg, 0, 1, IS_MIXED, 0)
1010
ZEND_ARG_TYPE_INFO(0, arg_num, IS_LONG, 0)
1111
ZEND_END_ARG_INFO()
1212

Zend/zend_closures.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ public static function bind(Closure $closure, ?object $newthis, $newscope = UNKN
1111
/** @alias Closure::bind */
1212
public function bindTo(?object $newthis, $newscope = UNKNOWN): ?Closure {}
1313

14-
/** @return mixed */
15-
public function call(object $newthis, ...$parameters) {}
14+
public function call(object $newthis, mixed ...$parameters): mixed {}
1615

1716
/** @param callable $callable Not a proper type annotation due to bug #78770 */
1817
public static function fromCallable($callable): Closure {}

Zend/zend_closures_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Closure_bindTo, 0, 1, Closu
1414
ZEND_ARG_INFO(0, newscope)
1515
ZEND_END_ARG_INFO()
1616

17-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Closure_call, 0, 0, 1)
17+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Closure_call, 0, 1, IS_MIXED, 0)
1818
ZEND_ARG_TYPE_INFO(0, newthis, IS_OBJECT, 0)
19-
ZEND_ARG_VARIADIC_INFO(0, parameters)
19+
ZEND_ARG_VARIADIC_TYPE_INFO(0, parameters, IS_MIXED, 0)
2020
ZEND_END_ARG_INFO()
2121

2222
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Closure_fromCallable, 0, 1, Closure, 0)

Zend/zend_generators.stub.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@ public function rewind(): void {}
88

99
public function valid(): bool {}
1010

11-
/** @return mixed */
12-
public function current() {}
11+
public function current(): mixed {}
1312

14-
/** @return mixed */
15-
public function key() {}
13+
public function key(): mixed {}
1614

1715
public function next(): void {}
1816

19-
/** @return mixed */
20-
public function send($value) {}
17+
public function send(mixed $value): mixed {}
2118

22-
/** @return mixed */
23-
public function throw(Throwable $exception) {}
19+
public function throw(Throwable $exception): mixed {}
2420

25-
/** @return mixed */
26-
public function getReturn() {}
21+
public function getReturn(): mixed {}
2722
}

Zend/zend_generators_arginfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ ZEND_END_ARG_INFO()
66
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_valid, 0, 0, _IS_BOOL, 0)
77
ZEND_END_ARG_INFO()
88

9-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Generator_current, 0, 0, 0)
9+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_current, 0, 0, IS_MIXED, 0)
1010
ZEND_END_ARG_INFO()
1111

1212
#define arginfo_class_Generator_key arginfo_class_Generator_current
1313

1414
#define arginfo_class_Generator_next arginfo_class_Generator_rewind
1515

16-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Generator_send, 0, 0, 1)
17-
ZEND_ARG_INFO(0, value)
16+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_send, 0, 1, IS_MIXED, 0)
17+
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
1818
ZEND_END_ARG_INFO()
1919

20-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Generator_throw, 0, 0, 1)
20+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_throw, 0, 1, IS_MIXED, 0)
2121
ZEND_ARG_OBJ_INFO(0, exception, Throwable, 0)
2222
ZEND_END_ARG_INFO()
2323

build/gen_stub.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function __construct(string $name, bool $isBuiltin) {
6565

6666
public static function fromNode(Node $node) {
6767
if ($node instanceof Node\Name) {
68+
if ($node->toString() === "mixed") {
69+
return new SimpleType($node->toString(), true);
70+
}
71+
6872
assert($node->isFullyQualified());
6973
return new SimpleType($node->toString(), false);
7074
}
@@ -97,6 +101,8 @@ public function toTypeCode() {
97101
return "IS_VOID";
98102
case "callable":
99103
return "IS_CALLABLE";
104+
case "mixed":
105+
return "IS_MIXED";
100106
default:
101107
throw new Exception("Not implemented: $this->name");
102108
}
@@ -123,6 +129,8 @@ public function toTypeMask() {
123129
return "MAY_BE_OBJECT";
124130
case "callable":
125131
return "MAY_BE_CALLABLE";
132+
case "mixed":
133+
return "MAY_BE_ANY";
126134
default:
127135
throw new Exception("Not implemented: $this->name");
128136
}
@@ -637,8 +645,11 @@ function parseFunctionLike(
637645
$param->default->name->toLowerString() === "null" &&
638646
$type && !$type->isNullable()
639647
) {
640-
throw new Exception(
641-
"Parameter $varName of function $name has null default, but is not nullable");
648+
$simpleType = $type->tryToSimpleType();
649+
if ($simpleType === null || $simpleType->name !== "mixed") {
650+
throw new Exception(
651+
"Parameter $varName of function $name has null default, but is not nullable");
652+
}
642653
}
643654

644655
$foundVariadic = $param->variadic;

ext/filter/filter.stub.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,17 @@
44

55
function filter_has_var(int $type, string $variable_name): bool {}
66

7-
/**
8-
* @param mixed $options
9-
* @return mixed
10-
*/
11-
function filter_input(int $type, string $variable_name, int $filter = FILTER_DEFAULT, $options = null) {}
12-
13-
/**
14-
* @param mixed $variable
15-
* @param mixed $options
16-
* @return mixed
17-
*/
18-
function filter_var($variable, int $filter = FILTER_DEFAULT, $options = null) {}
19-
20-
/**
21-
* @param mixed $options
22-
* @return mixed
23-
*/
24-
function filter_input_array(int $type, $options = FILTER_DEFAULT, bool $add_empty = true) {}
25-
26-
/**
27-
* @param mixed $options
28-
* @return mixed
29-
*/
30-
function filter_var_array(array $data, $options = FILTER_DEFAULT, bool $add_empty = true) {}
7+
/** @param array|int $options */
8+
function filter_input(int $type, string $variable_name, int $filter = FILTER_DEFAULT, $options = null): mixed {}
9+
10+
/** @param array|int $options */
11+
function filter_var(mixed $variable, int $filter = FILTER_DEFAULT, $options = null): mixed {}
12+
13+
/** @param array|int $options */
14+
function filter_input_array(int $type, $options = FILTER_DEFAULT, bool $add_empty = true): array|false|null {}
15+
16+
/** @param array|int $options */
17+
function filter_var_array(array $data, $options = FILTER_DEFAULT, bool $add_empty = true): array|false|null {}
3118

3219
function filter_list(): array {}
3320

ext/filter/filter_arginfo.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_filter_has_var, 0, 2, _IS_BOOL,
55
ZEND_ARG_TYPE_INFO(0, variable_name, IS_STRING, 0)
66
ZEND_END_ARG_INFO()
77

8-
ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_input, 0, 0, 2)
8+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_filter_input, 0, 2, IS_MIXED, 0)
99
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
1010
ZEND_ARG_TYPE_INFO(0, variable_name, IS_STRING, 0)
1111
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filter, IS_LONG, 0, "FILTER_DEFAULT")
1212
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, options, "null")
1313
ZEND_END_ARG_INFO()
1414

15-
ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_var, 0, 0, 1)
16-
ZEND_ARG_INFO(0, variable)
15+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_filter_var, 0, 1, IS_MIXED, 0)
16+
ZEND_ARG_TYPE_INFO(0, variable, IS_MIXED, 0)
1717
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filter, IS_LONG, 0, "FILTER_DEFAULT")
1818
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, options, "null")
1919
ZEND_END_ARG_INFO()
2020

21-
ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_input_array, 0, 0, 1)
21+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_filter_input_array, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE|MAY_BE_NULL)
2222
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
2323
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, options, "FILTER_DEFAULT")
2424
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, add_empty, _IS_BOOL, 0, "true")
2525
ZEND_END_ARG_INFO()
2626

27-
ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_var_array, 0, 0, 1)
27+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_filter_var_array, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE|MAY_BE_NULL)
2828
ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
2929
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, options, "FILTER_DEFAULT")
3030
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, add_empty, _IS_BOOL, 0, "true")

ext/json/json.stub.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
/** @generate-function-entries */
44

5-
function json_encode($value, int $options = 0, int $depth = 512): string|false {}
5+
function json_encode(mixed $value, int $options = 0, int $depth = 512): string|false {}
66

7-
/** @return mixed */
8-
function json_decode(string $json, ?bool $assoc = null, int $depth = 512, int $options = 0) {}
7+
function json_decode(string $json, ?bool $assoc = null, int $depth = 512, int $options = 0): mixed {}
98

109
function json_last_error(): int {}
1110

ext/json/json_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* This is a generated file, edit the .stub.php file instead. */
22

33
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_json_encode, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
4-
ZEND_ARG_INFO(0, value)
4+
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "0")
66
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, depth, IS_LONG, 0, "512")
77
ZEND_END_ARG_INFO()
88

9-
ZEND_BEGIN_ARG_INFO_EX(arginfo_json_decode, 0, 0, 1)
9+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_json_decode, 0, 1, IS_MIXED, 0)
1010
ZEND_ARG_TYPE_INFO(0, json, IS_STRING, 0)
1111
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, assoc, _IS_BOOL, 1, "null")
1212
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, depth, IS_LONG, 0, "512")

ext/mysqli/mysqli.stub.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public function attr_set(int $attr, int $mode_in) {}
407407
* @return bool
408408
* @alias mysqli_stmt_bind_param
409409
*/
410-
public function bind_param(string $types, &...$vars) {}
410+
public function bind_param(string $types, mixed &...$vars) {}
411411

412412
/**
413413
* @return bool
@@ -681,8 +681,7 @@ function mysqli_stmt_attr_get(mysqli_stmt $mysql_stmt, int $attr): int|false {}
681681

682682
function mysqli_stmt_attr_set(mysqli_stmt $mysql_stmt, int $attr, int $mode_in): bool {}
683683

684-
/** @param mixed &...$vars */
685-
function mysqli_stmt_bind_param(mysqli_stmt $mysql_stmt, string $types, &...$vars): bool {}
684+
function mysqli_stmt_bind_param(mysqli_stmt $mysql_stmt, string $types, mixed &...$vars): bool {}
686685

687686
/** @param mixed &...$vars */
688687
function mysqli_stmt_bind_result(mysqli_stmt $mysql_stmt, &...$vars): bool {}

ext/mysqli/mysqli_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ ZEND_END_ARG_INFO()
298298
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_stmt_bind_param, 0, 2, _IS_BOOL, 0)
299299
ZEND_ARG_OBJ_INFO(0, mysql_stmt, mysqli_stmt, 0)
300300
ZEND_ARG_TYPE_INFO(0, types, IS_STRING, 0)
301-
ZEND_ARG_VARIADIC_INFO(1, vars)
301+
ZEND_ARG_VARIADIC_TYPE_INFO(1, vars, IS_MIXED, 0)
302302
ZEND_END_ARG_INFO()
303303

304304
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_stmt_bind_result, 0, 1, _IS_BOOL, 0)
@@ -633,7 +633,7 @@ ZEND_END_ARG_INFO()
633633

634634
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_stmt_bind_param, 0, 0, 1)
635635
ZEND_ARG_TYPE_INFO(0, types, IS_STRING, 0)
636-
ZEND_ARG_VARIADIC_INFO(1, vars)
636+
ZEND_ARG_VARIADIC_TYPE_INFO(1, vars, IS_MIXED, 0)
637637
ZEND_END_ARG_INFO()
638638

639639
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_stmt_bind_result, 0, 0, 0)

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static const func_info_t func_infos[] = {
214214
F1("password_get_info", MAY_BE_NULL | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY),
215215
F1("convert_uuencode", MAY_BE_FALSE | MAY_BE_STRING),
216216
F1("convert_uudecode", MAY_BE_FALSE | MAY_BE_STRING),
217-
F1("pow", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_DOUBLE | MAY_BE_OBJECT),
217+
F1("pow", MAY_BE_LONG | MAY_BE_DOUBLE | MAY_BE_OBJECT),
218218
F1("decbin", MAY_BE_STRING),
219219
F1("decoct", MAY_BE_STRING),
220220
F1("dechex", MAY_BE_STRING),

ext/pdo/pdo_dbh.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function errorInfo() {}
2121
/** @return int|false */
2222
public function exec(string $statement) {}
2323

24-
/** @return mixed */
24+
/** @return bool|int|string|array|null */
2525
public function getAttribute(int $attribute) {}
2626

2727
/** @return array */

ext/reflection/php_reflection.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function __toString(): string {}
111111
public function isDisabled() {}
112112

113113
/** @return mixed */
114-
public function invoke(...$args) {}
114+
public function invoke(mixed ...$args) {}
115115

116116
/** @return mixed */
117117
public function invokeArgs(array $args) {}
@@ -181,7 +181,7 @@ public function getClosure($object = UNKNOWN) {}
181181
public function getModifiers() {}
182182

183183
/** @return mixed */
184-
public function invoke(?object $object = null, ...$args) {}
184+
public function invoke(?object $object = null, mixed ...$args) {}
185185

186186
/** @return mixed */
187187
public function invokeArgs(?object $object, array $args) {}

ext/reflection/php_reflection_arginfo.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ ZEND_END_ARG_INFO()
6767
#define arginfo_class_ReflectionFunction_isDisabled arginfo_class_ReflectionFunctionAbstract___clone
6868

6969
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionFunction_invoke, 0, 0, 0)
70-
ZEND_ARG_VARIADIC_INFO(0, args)
70+
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0)
7171
ZEND_END_ARG_INFO()
7272

7373
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionFunction_invokeArgs, 0, 0, 1)
@@ -125,7 +125,7 @@ ZEND_END_ARG_INFO()
125125

126126
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionMethod_invoke, 0, 0, 0)
127127
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, object, IS_OBJECT, 1, "null")
128-
ZEND_ARG_VARIADIC_INFO(0, args)
128+
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0)
129129
ZEND_END_ARG_INFO()
130130

131131
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionMethod_invokeArgs, 0, 0, 2)
@@ -221,7 +221,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_isInstance, 0, 0, 1)
221221
ZEND_ARG_TYPE_INFO(0, object, IS_OBJECT, 0)
222222
ZEND_END_ARG_INFO()
223223

224-
#define arginfo_class_ReflectionClass_newInstance arginfo_class_ReflectionFunction_invoke
224+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_newInstance, 0, 0, 0)
225+
ZEND_ARG_VARIADIC_INFO(0, args)
226+
ZEND_END_ARG_INFO()
225227

226228
#define arginfo_class_ReflectionClass_newInstanceWithoutConstructor arginfo_class_ReflectionFunctionAbstract___clone
227229

0 commit comments

Comments
 (0)