summaryrefslogtreecommitdiff
path: root/Zend/tests/match/017.phpt
blob: 622f7bb165105ec61e9d6c0ff6935ae6e51fa01b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--TEST--
Test strict comparison with match expression jump table
--FILE--
<?php

function wrong() {
    throw new Exception();
}

function test_int($char) {
    return match ($char) {
        0 => wrong(),
        1 => wrong(),
        2 => wrong(),
        3 => wrong(),
        4 => wrong(),
        5 => wrong(),
        6 => wrong(),
        7 => wrong(),
        8 => wrong(),
        9 => wrong(),
        default => 'Not matched',
    };
}

foreach (range(0, 9) as $int) {
    var_dump((string) $int);
    var_dump(test_int((string) $int));
}

function test_string($int) {
    return match ($int) {
        '0' => wrong(),
        '1' => wrong(),
        '2' => wrong(),
        '3' => wrong(),
        '4' => wrong(),
        '5' => wrong(),
        '6' => wrong(),
        '7' => wrong(),
        '8' => wrong(),
        '9' => wrong(),
        default => 'Not matched',
    };
}

foreach (range(0, 9) as $int) {
    var_dump($int);
    var_dump(test_string($int));
}

--EXPECT--
string(1) "0"
string(11) "Not matched"
string(1) "1"
string(11) "Not matched"
string(1) "2"
string(11) "Not matched"
string(1) "3"
string(11) "Not matched"
string(1) "4"
string(11) "Not matched"
string(1) "5"
string(11) "Not matched"
string(1) "6"
string(11) "Not matched"
string(1) "7"
string(11) "Not matched"
string(1) "8"
string(11) "Not matched"
string(1) "9"
string(11) "Not matched"
int(0)
string(11) "Not matched"
int(1)
string(11) "Not matched"
int(2)
string(11) "Not matched"
int(3)
string(11) "Not matched"
int(4)
string(11) "Not matched"
int(5)
string(11) "Not matched"
int(6)
string(11) "Not matched"
int(7)
string(11) "Not matched"
int(8)
string(11) "Not matched"
int(9)
string(11) "Not matched"