blob: e80dfbb7d14d6864c7ed0ef6107075c62a94c968 (
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
|
--TEST--
Test throw with various expressions
--FILE--
<?php
class Foo {
public function createNotFoundException() {
return new Exception('Not found');
}
public function throwException() {
throw $this->createNotFoundException();
}
public static function staticCreateNotFoundException() {
return new Exception('Static not found');
}
public static function staticThrowException() {
throw static::staticCreateNotFoundException();
}
}
try {
(new Foo())->throwException();
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
try {
Foo::staticThrowException();
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
try {
throw true ? new Exception('Ternary true 1') : new Exception('Ternary true 2');
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
try {
throw false ? new Exception('Ternary false 1') : new Exception('Ternary false 2');
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
try {
$exception1 = new Exception('Coalesce non-null 1');
$exception2 = new Exception('Coalesce non-null 2');
throw $exception1 ?? $exception2;
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
try {
$exception1 = null;
$exception2 = new Exception('Coalesce null 2');
throw $exception1 ?? $exception2;
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
try {
throw $exception = new Exception('Assignment');
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
try {
$exception = null;
throw $exception ??= new Exception('Coalesce assignment null');
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
try {
$exception = new Exception('Coalesce assignment non-null 1');
throw $exception ??= new Exception('Coalesce assignment non-null 2');
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
$andConditionalTest = function ($condition1, $condition2) {
throw $condition1 && $condition2
? new Exception('And in conditional 1')
: new Exception('And in conditional 2');
};
try {
$andConditionalTest(false, false);
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
try {
$andConditionalTest(false, true);
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
try {
$andConditionalTest(true, false);
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
try {
$andConditionalTest(true, true);
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
?>
--EXPECT--
Not found
Static not found
Ternary true 1
Ternary false 2
Coalesce non-null 1
Coalesce null 2
Assignment
Coalesce assignment null
Coalesce assignment non-null 1
And in conditional 2
And in conditional 2
And in conditional 2
And in conditional 1
|