summaryrefslogtreecommitdiff
path: root/Zend/tests/throw/001.phpt
blob: deb8743ab5667ff98cfbc38d73bdd73cc4ddedaf (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
--TEST--
throw expression
--FILE--
<?php

try {
    $result = true && throw new Exception("true && throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = false && throw new Exception("false && throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = true and throw new Exception("true and throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = false and throw new Exception("false and throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = true || throw new Exception("true || throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = false || throw new Exception("false || throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = true or throw new Exception("true or throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = false or throw new Exception("false or throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = null ?? throw new Exception("null ?? throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = "foo" ?? throw new Exception('"foo" ?? throw');
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = null ?: throw new Exception("null ?: throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = "foo" ?: throw new Exception('"foo" ?: throw');
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $callable = fn() => throw new Exception("fn() => throw");
    var_dump("not yet");
    $callable();
} catch (Exception $e) {
    var_dump($e->getMessage());
}

$result = "bar";
try {
    $result = throw new Exception();
} catch (Exception $e) {}
var_dump($result);

try {
    var_dump(
        throw new Exception("exception 1"),
        throw new Exception("exception 2")
    );
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = true ? true : throw new Exception("true ? true : throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    $result = false ? true : throw new Exception("false ? true : throw");
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
}

try {
    throw new Exception() + 1;
} catch (Throwable $e) {
    var_dump($e->getMessage());
}

try {
    throw $exception = new Exception('throw $exception = new Exception();');
} catch (Exception $e) {}
var_dump($exception->getMessage());

try {
    $exception = null;
    throw $exception ??= new Exception('throw $exception ??= new Exception();');
} catch (Exception $e) {}
var_dump($exception->getMessage());

try {
    throw null ?? new Exception('throw null ?? new Exception();');
} catch (Exception $e) {
    var_dump($e->getMessage());
}

?>
--EXPECT--
string(13) "true && throw"
bool(false)
string(14) "true and throw"
bool(false)
bool(true)
string(14) "false || throw"
bool(true)
string(14) "false or throw"
string(13) "null ?? throw"
string(3) "foo"
string(13) "null ?: throw"
string(3) "foo"
string(7) "not yet"
string(13) "fn() => throw"
string(3) "bar"
string(11) "exception 1"
bool(true)
string(20) "false ? true : throw"
string(39) "Unsupported operand types: object + int"
string(35) "throw $exception = new Exception();"
string(37) "throw $exception ??= new Exception();"
string(30) "throw null ?? new Exception();"