xref: /PHP-8.0/tests/lang/foreachLoop.003.phpt (revision f44dd16b)
1--TEST--
2Foreach loop tests - error case: not an array.
3--FILE--
4<?php
5echo "\nNot an array.\n";
6$a = TRUE;
7foreach ($a as $v) {
8    var_dump($v);
9}
10
11$a = null;
12foreach ($a as $v) {
13    var_dump($v);
14}
15
16$a = 1;
17foreach ($a as $v) {
18    var_dump($v);
19}
20
21$a = 1.5;
22foreach ($a as $v) {
23    var_dump($v);
24}
25
26$a = "hello";
27foreach ($a as $v) {
28    var_dump($v);
29}
30
31echo "done.\n";
32?>
33--EXPECTF--
34Not an array.
35
36Warning: foreach() argument must be of type array|object, bool given in %s on line 4
37
38Warning: foreach() argument must be of type array|object, null given in %s on line 9
39
40Warning: foreach() argument must be of type array|object, int given in %s on line 14
41
42Warning: foreach() argument must be of type array|object, float given in %s on line 19
43
44Warning: foreach() argument must be of type array|object, string given in %s on line 24
45done.
46