1 | <?php |
||
8 | trait HandleShutdownError |
||
9 | { |
||
10 | /** |
||
11 | * @var boolean |
||
12 | */ |
||
13 | protected $registeredShutdown = false; |
||
14 | |||
15 | /** |
||
16 | * A string which reserves memory that can be used to log the error in case of an out of memory fatal error |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $reservedMemory; |
||
20 | |||
21 | |||
22 | /** |
||
23 | * Run the fatal error callback |
||
24 | * |
||
25 | * @param \Exception|\Error $error |
||
26 | */ |
||
27 | abstract protected function callOnFatalError($error); |
||
28 | |||
29 | /** |
||
30 | * Wrapper method for `error_get_last` |
||
31 | * |
||
32 | * @return array |
||
33 | */ |
||
34 | abstract protected function errorGetLast(); |
||
35 | |||
36 | /** |
||
37 | * Wrapper method for `register_shutdown_function` |
||
38 | * |
||
39 | * @param callable $callback |
||
40 | */ |
||
41 | abstract protected function registerShutdownFunction($callback); |
||
42 | |||
43 | /** |
||
44 | * Log an error or exception |
||
45 | * |
||
46 | * @param \Exception|\Error $error |
||
47 | */ |
||
48 | abstract public function log($error); |
||
49 | |||
50 | |||
51 | /** |
||
52 | * Reserve memory for shutdown function in case of out of memory |
||
53 | */ |
||
54 | 32 | protected function reserveMemory() |
|
58 | |||
59 | /** |
||
60 | * Register the shutdown function |
||
61 | */ |
||
62 | 32 | protected function initShutdownFunction() |
|
71 | |||
72 | /** |
||
73 | * Called when the script has ends |
||
74 | * @ignore |
||
75 | */ |
||
76 | 16 | public function shutdownFunction() |
|
95 | } |
||
96 | |||
97 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.