You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Convert iterable into an internal alias for Traversable|array (#7309)
This does a compile time transformation of ``iterable`` into ``Traversable|array`` which simplifies some of the LSP variance handling.
The arginfo generation script from stubs is updated to produce a union type when it encounters the type ``iterable``
Extension functions which do not regenerate the arginfo, or write them manually are still supported by mimicking the compile time transformation while registering the function.
Type Reflection is preserved for single ``iterable`` (and ``?iterable``) to produce a ReflectionNamedType with name ``iterable``, however usage of ``iterable`` in union types will be converted to ``array|Traversable``
Test "or null"/"or be null" in type-checking errors for userland functions with iterable
3
+
--FILE--
4
+
<?php
5
+
6
+
// This should test every branch in zend_execute.c's `zend_verify_arg_type`, `zend_verify_return_type` and `zend_verify_missing_return_type` functions which produces an "or null"/"or be null" part in its error message
7
+
8
+
functioniterableF(?iterable$param) {}
9
+
try {
10
+
iterableF(1);
11
+
} catch (\TypeError$e) {
12
+
echo$e, PHP_EOL;
13
+
}
14
+
15
+
functionreturnIterable(): ?iterable {
16
+
return1;
17
+
}
18
+
19
+
try {
20
+
returnIterable();
21
+
} catch (\TypeError$e) {
22
+
echo$e, PHP_EOL;
23
+
}
24
+
25
+
functionreturnMissingIterable(): ?iterable {
26
+
}
27
+
28
+
try {
29
+
returnMissingIterable();
30
+
} catch (\TypeError$e) {
31
+
echo$e, PHP_EOL;
32
+
}
33
+
?>
34
+
--EXPECTF--
35
+
TypeError: iterableF(): Argument #1 ($param) must be of type Traversable|array|null, int given, called in %s on line %d and defined in %s:%d
36
+
Stack trace:
37
+
#0 %s(%d): iterableF(1)
38
+
#1 {main}
39
+
TypeError: returnIterable(): Return value must be of type Traversable|array|null, int returned in %s:%d
40
+
Stack trace:
41
+
#0 %s(%d): returnIterable()
42
+
#1 {main}
43
+
TypeError: returnMissingIterable(): Return value must be of type Traversable|array|null, none returned in %s:%d
0 commit comments