xref: /PHP-8.0/Zend/tests/iterable_or_null.phpt (revision 94fd52dd)
1--TEST--
2Test Z_PARAM_ITERABLE() and Z_PARAM_ITERABLE_OR_NULL
3--SKIPIF--
4<?php
5if (!extension_loaded('zend-test')) die('skip zend-test extension not loaded');
6?>
7--FILE--
8<?php
9
10try {
11	  var_dump(zend_iterable("string"));
12} catch (TypeError $exception) {
13    echo $exception->getMessage() . "\n";
14}
15
16try {
17	  var_dump(zend_iterable(1));
18} catch (TypeError $exception) {
19    echo $exception->getMessage() . "\n";
20}
21
22try {
23	  var_dump(zend_iterable(null));
24} catch (TypeError $exception) {
25    echo $exception->getMessage() . "\n";
26}
27
28
29zend_iterable([]);
30zend_iterable([], []);
31
32$iterator = new ArrayIterator([]);
33zend_iterable($iterator);
34zend_iterable($iterator, $iterator);
35zend_iterable($iterator, null);
36
37try {
38	  var_dump(zend_iterable([], "string"));
39} catch (TypeError $exception) {
40    echo $exception->getMessage() . "\n";
41}
42
43?>
44--EXPECT--
45zend_iterable(): Argument #1 ($arg1) must be of type iterable, string given
46zend_iterable(): Argument #1 ($arg1) must be of type iterable, int given
47zend_iterable(): Argument #1 ($arg1) must be of type iterable, null given
48zend_iterable(): Argument #2 ($arg2) must be of type ?iterable, string given
49
50