1--TEST--
2Test "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
8function iterableF(?iterable $param) {}
9try {
10    iterableF(1);
11} catch (\TypeError $e) {
12    echo $e, PHP_EOL;
13}
14
15function returnIterable(): ?iterable {
16    return 1;
17}
18
19try {
20    returnIterable();
21} catch (\TypeError $e) {
22    echo $e, PHP_EOL;
23}
24
25function returnMissingIterable(): ?iterable {
26}
27
28try {
29    returnMissingIterable();
30} catch (\TypeError $e) {
31    echo $e, PHP_EOL;
32}
33?>
34--EXPECTF--
35TypeError: iterableF(): Argument #1 ($param) must be of type Traversable|array|null, int given, called in %s on line %d and defined in %s:%d
36Stack trace:
37#0 %s(%d): iterableF(1)
38#1 {main}
39TypeError: returnIterable(): Return value must be of type Traversable|array|null, int returned in %s:%d
40Stack trace:
41#0 %s(%d): returnIterable()
42#1 {main}
43TypeError: returnMissingIterable(): Return value must be of type Traversable|array|null, none returned in %s:%d
44Stack trace:
45#0 %s(%d): returnMissingIterable()
46#1 {main}
47