xref: /PHP-8.0/Zend/tests/match/037.phpt (revision 1c967df5)
1--TEST--
2Test match jumptable with only one arm
3--FILE--
4<?php
5
6try {
7    var_dump(match(true) {
8        1, 2, 3, 4, 5 => 'foo',
9    });
10} catch (Error $e) {
11    var_dump((string) $e);
12}
13
14try {
15    var_dump(match(6) {
16        1, 2, 3, 4, 5 => 'foo',
17    });
18} catch (Error $e) {
19    var_dump((string) $e);
20}
21
22try {
23    var_dump(match('3') {
24        1, 2, 3, 4, 5 => 'foo',
25    });
26} catch (Error $e) {
27    var_dump((string) $e);
28}
29
30var_dump(match(3) {
31    1, 2, 3, 4, 5 => 'foo',
32});
33
34var_dump(match(true) {
35    1, 2, 3, 4, 5 => 'foo',
36    default => 'bar',
37});
38
39var_dump(match(6) {
40    1, 2, 3, 4, 5 => 'foo',
41    default => 'bar',
42});
43
44var_dump(match('3') {
45    1, 2, 3, 4, 5 => 'foo',
46    default => 'bar',
47});
48
49var_dump(match(3) {
50    1, 2, 3, 4, 5 => 'foo',
51    default => 'bar',
52});
53
54?>
55--EXPECTF--
56string(%d) "UnhandledMatchError: Unhandled match value of type bool in %s037.php:4
57Stack trace:
58#0 {main}"
59string(%d) "UnhandledMatchError: Unhandled match value of type int in %s037.php:12
60Stack trace:
61#0 {main}"
62string(%d) "UnhandledMatchError: Unhandled match value of type string in %s037.php:20
63Stack trace:
64#0 {main}"
65string(3) "foo"
66string(3) "bar"
67string(3) "bar"
68string(3) "bar"
69string(3) "foo"
70