xref: /PHP-8.1/Zend/tests/match/017.phpt (revision d5a03708)
1--TEST--
2Test strict comparison with match expression jump table
3--FILE--
4<?php
5
6function wrong() {
7    throw new Exception();
8}
9
10function test_int($char) {
11    return match ($char) {
12        0 => wrong(),
13        1 => wrong(),
14        2 => wrong(),
15        3 => wrong(),
16        4 => wrong(),
17        5 => wrong(),
18        6 => wrong(),
19        7 => wrong(),
20        8 => wrong(),
21        9 => wrong(),
22        default => 'Not matched',
23    };
24}
25
26foreach (range(0, 9) as $int) {
27    var_dump((string) $int);
28    var_dump(test_int((string) $int));
29}
30
31function test_string($int) {
32    return match ($int) {
33        '0' => wrong(),
34        '1' => wrong(),
35        '2' => wrong(),
36        '3' => wrong(),
37        '4' => wrong(),
38        '5' => wrong(),
39        '6' => wrong(),
40        '7' => wrong(),
41        '8' => wrong(),
42        '9' => wrong(),
43        default => 'Not matched',
44    };
45}
46
47foreach (range(0, 9) as $int) {
48    var_dump($int);
49    var_dump(test_string($int));
50}
51
52?>
53--EXPECT--
54string(1) "0"
55string(11) "Not matched"
56string(1) "1"
57string(11) "Not matched"
58string(1) "2"
59string(11) "Not matched"
60string(1) "3"
61string(11) "Not matched"
62string(1) "4"
63string(11) "Not matched"
64string(1) "5"
65string(11) "Not matched"
66string(1) "6"
67string(11) "Not matched"
68string(1) "7"
69string(11) "Not matched"
70string(1) "8"
71string(11) "Not matched"
72string(1) "9"
73string(11) "Not matched"
74int(0)
75string(11) "Not matched"
76int(1)
77string(11) "Not matched"
78int(2)
79string(11) "Not matched"
80int(3)
81string(11) "Not matched"
82int(4)
83string(11) "Not matched"
84int(5)
85string(11) "Not matched"
86int(6)
87string(11) "Not matched"
88int(7)
89string(11) "Not matched"
90int(8)
91string(11) "Not matched"
92int(9)
93string(11) "Not matched"
94