forked from krakjoe/pthreads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexception-handler-options.phpt
54 lines (43 loc) · 1.17 KB
/
exception-handler-options.phpt
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
--TEST--
Test exception handler inheritance (options)
--DESCRIPTION--
PTHREADS_INHERIT_CLASSES and PTHREADS_INHERIT_FUNCTIONS effect the handlers that can be copied.
This test ensures that the various options are sensibly covered, and hopefully nothing crashes.
--FILE--
<?php
class Handler {
public function handle(Throwable $ex) {
var_dump(__METHOD__, $ex->getMessage());
}
}
class Test extends Thread {
public function run () {
throw new Exception("oh dear");
}
}
$handler = new Handler();
set_exception_handler([$handler, "handle"]); # needs classes
$test = new Test();
$test->start(PTHREADS_INHERIT_FUNCTIONS); # uncaught
$test->join();
$test = new Test();
$test->start(PTHREADS_INHERIT_CLASSES); # caught
$test->join();
restore_exception_handler();
set_exception_handler(function($ex){
var_dump(__FUNCTION__, $ex->getMessage());
});
$test = new Test();
$test->start(PTHREADS_INHERIT_FUNCTIONS); # caught
$test->join();
?>
--EXPECTF--
Fatal error: Uncaught Exception: oh dear in %s:10
Stack trace:
#0 [internal function]: Test->run()
#1 {main}
thrown in %s on line 10
string(15) "Handler::handle"
string(7) "oh dear"
string(9) "{closure}"
string(7) "oh dear"