forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththrowing_error_handler_001.phpt
More file actions
91 lines (77 loc) · 1.95 KB
/
Copy paththrowing_error_handler_001.phpt
File metadata and controls
91 lines (77 loc) · 1.95 KB
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
--TEST--
#[\Deprecated]: Throwing error handler.
--FILE--
<?php
set_error_handler(function (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null) {
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
}, delay: false);
#[\Deprecated("convert to exception")]
function test() {
echo "Not executed", PHP_EOL;
}
try {
test();
} catch (ErrorException $e) {
echo "Caught: ", $e->getMessage(), PHP_EOL;
}
eval(<<<'CODE'
#[\Deprecated("convert to exception")]
function test2() {
echo "Not executed", PHP_EOL;
}
CODE);
try {
test2();
} catch (ErrorException $e) {
echo "Caught: ", $e->getMessage(), PHP_EOL;
}
class Clazz {
#[\Deprecated("convert to exception")]
function test() {
echo "Not executed", PHP_EOL;
}
}
try {
$cls = new Clazz();
$cls->test();
} catch (ErrorException $e) {
echo "Caught: ", $e->getMessage(), PHP_EOL;
}
$closure = #[\Deprecated("convert to exception")] function () {
echo "Not executed", PHP_EOL;
};
try {
$closure();
} catch (ErrorException $e) {
echo "Caught: ", $e->getMessage(), PHP_EOL;
}
class Constructor {
#[\Deprecated("convert to exception")]
public function __construct() {
echo "Not executed", PHP_EOL;
}
}
try {
new Constructor();
} catch (ErrorException $e) {
echo "Caught: ", $e->getMessage(), PHP_EOL;
}
class Destructor {
#[\Deprecated("convert to exception")]
public function __destruct() {
echo "Not executed", PHP_EOL;
}
}
try {
(function () { new Destructor(); })();
} catch (ErrorException $e) {
echo "Caught: ", $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
Caught: Function test() is deprecated, convert to exception
Caught: Function test2() is deprecated, convert to exception
Caught: Method Clazz::test() is deprecated, convert to exception
Caught: Function {closure:%s:%d}() is deprecated, convert to exception
Caught: Method Constructor::__construct() is deprecated, convert to exception
Caught: Method Destructor::__destruct() is deprecated, convert to exception