reference/errorfunc/functions/set-exception-handler.xml
686b6869e2695d96d0f3a2055cfa629a8b3b1ac7
...
...
@@ -11,13 +11,13 @@
11
11
<refsect1 role="description">
12
12
&reftitle.description;
13
13
<methodsynopsis>
14
-
<type>callable</type><methodname>set_exception_handler</methodname>
15
-
<methodparam><type>callable</type><parameter>exception_handler</parameter></methodparam>
14
+
<type class="union"><type>callable</type><type>null</type></type><methodname>set_exception_handler</methodname>
15
+
<methodparam><type class="union"><type>callable</type><type>null</type></type><parameter>callback</parameter></methodparam>
16
16
</methodsynopsis>
17
17
<para>
18
18
Sets the default exception handler if an exception is not caught within a
19
19
try/catch block. Execution will stop after the
20
-
<parameter>exception_handler</parameter> is called.
20
+
<parameter>callback</parameter> is called.
21
21
</para>
22
22
</refsect1>
23
23

...
...
@@ -26,25 +26,15 @@
26
26
<para>
27
27
<variablelist>
28
28
<varlistentry>
29
-
<term><parameter>exception_handler</parameter></term>
29
+
<term><parameter>callback</parameter></term>
30
30
<listitem>
31
31
<para>
32
-
Name of the function to be called when an uncaught exception occurs.
33
-
This handler function
34
-
needs to accept one parameter, which will be the exception object that
35
-
was thrown. This is the handler signature before PHP 7:
36
-
</para>
37
-
<para>
38
-
<methodsynopsis>
39
-
<type>void</type><methodname><replaceable>handler</replaceable></methodname>
40
-
<methodparam><type>Exception</type><parameter>ex</parameter></methodparam>
41
-
</methodsynopsis>
42
-
</para>
43
-
<para>
44
-
Since PHP 7, most errors are reported by throwing <classname>Error</classname>
45
-
exceptions, which will be caught by the handler as well. Both <classname>Error</classname>
46
-
and <classname>Exception</classname> implements the <classname>Throwable</classname> interface.
47
-
This is the handler signature since PHP 7:
32
+
The function to be called when an uncaught exception occurs.
33
+
This handler function needs to accept one parameter,
34
+
which will be the <classname>Throwable</classname> object that was thrown.
35
+
Both <classname>Error</classname> and <classname>Exception</classname>
36
+
implement the <classname>Throwable</classname> interface.
37
+
This is the handler signature:
48
38
</para>
49
39
<para>
50
40
<methodsynopsis>
...
...
@@ -55,13 +45,6 @@
55
45
<para>
56
46
&null; may be passed instead, to reset this handler to its default state.
57
47
</para>
58
-
<caution>
59
-
<para>
60
-
Note that providing an explicit <classname>Exception</classname> type
61
-
hint for the <parameter>ex</parameter> parameter in your callback will
62
-
cause issues with the changed exception hierarchy in PHP 7.
63
-
</para>
64
-
</caution>
65
48
</listitem>
66
49
</varlistentry>
67
50
</variablelist>
...
...
@@ -71,43 +54,11 @@
71
54
<refsect1 role="returnvalues">
72
55
&reftitle.returnvalues;
73
56
<para>
74
-
Returns the name of the previously defined exception handler, or &null; on error. If
57
+
Returns the previously defined exception handler, or &null; on error. If
75
58
no previous handler was defined, &null; is also returned.
76
59
</para>
77
60
</refsect1>
78
61

79
-
<refsect1 role="changelog">
80
-
&reftitle.changelog;
81
-
<para>
82
-
<informaltable>
83
-
<tgroup cols="2">
84
-
<thead>
85
-
<row>
86
-
<entry>&Version;</entry>
87
-
<entry>&Description;</entry>
88
-
</row>
89
-
</thead>
90
-
<tbody>
91
-
<row>
92
-
<entry>7.0.0</entry>
93
-
<entry>
94
-
The type of parameter passed into <parameter>exception_handler</parameter> changed
95
-
from <classname>Exception</classname> to <classname>Throwable</classname>
96
-
</entry>
97
-
</row>
98
-
<row>
99
-
<entry>5.5.0</entry>
100
-
<entry>
101
-
Previously, if &null; was passed then this function returned &true;.
102
-
It returns the previous handler since PHP 5.5.0.
103
-
</entry>
104
-
</row>
105
-
</tbody>
106
-
</tgroup>
107
-
</informaltable>
108
-
</para>
109
-
</refsect1>
110
-

111
62
<refsect1 role="examples">
112
63
&reftitle.examples;
113
64
<para>
...
...
@@ -116,7 +67,7 @@
116
67
<programlisting role="php">
117
68
<![CDATA[
118
69
<?php
119
-
function exception_handler($exception) {
70
+
function exception_handler(Throwable $exception) {
120
71
echo "Uncaught exception: " , $exception->getMessage(), "\n";
121
72
}
122
73

...
...
@@ -138,13 +89,12 @@ echo "Not Executed\n";
138
89
<member><function>restore_exception_handler</function></member>
139
90
<member><function>restore_error_handler</function></member>
140
91
<member><function>error_reporting</function></member>
141
-
<member><link linkend="language.exceptions">PHP 5 Exceptions</link></member>
92
+
<member><link linkend="language.exceptions">Exceptions</link></member>
142
93
</simplelist>
143
94
</para>
144
95
</refsect1><!-- }}} -->
145
96

146
97
</refentry>
147
-

148
98
<!-- Keep this comment at the end of the file
149
99
Local variables:
150
100
mode: sgml
151
101