language/predefined/errorexception.xml
2f3c1237bc46a7e40dae35e9f3aec2c1b2fa23b8
...
...
@@ -1,11 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
-
<phpdoc:exceptionref xml:id="class.errorexception"
5
-
xmlns="http://docbook.org/ns/docbook"
6
-
xmlns:xlink="http://www.w3.org/1999/xlink"
7
-
xmlns:xi="http://www.w3.org/2001/XInclude"
8
-
xmlns:phpdoc="http://php.net/ns/phpdoc">
3
+
<reference xml:id="class.errorexception" role="exception" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
9
4
<title>ErrorException</title>
10
5
<titleabbrev>ErrorException</titleabbrev>
11
6
...
...
@@ -24,38 +19,41 @@
24
19
&reftitle.classsynopsis;
25
20
26
21
<!-- {{{ Synopsis -->
27
-
<classsynopsis>
28
-
<ooclass><classname>ErrorException</classname></ooclass>
29
-
30
-
<!-- {{{ Class synopsis -->
31
-
<classsynopsisinfo>
32
-
<ooclass>
33
-
<classname>ErrorException</classname>
34
-
</ooclass>
35
-
36
-
<ooclass>
37
-
<modifier>extends</modifier>
38
-
<classname>Exception</classname>
39
-
</ooclass>
40
-
</classsynopsisinfo>
41
-
<!-- }}} -->
22
+
<classsynopsis class="class">
23
+
<ooexception>
24
+
<exceptionname>ErrorException</exceptionname>
25
+
</ooexception>
26
+

27
+
<ooclass>
28
+
<modifier>extends</modifier>
29
+
<classname>Exception</classname>
30
+
</ooclass>
42
31

43
32
<classsynopsisinfo role="comment">&Properties;</classsynopsisinfo>
44
33
<fieldsynopsis>
45
34
<modifier>protected</modifier>
46
35
<type>int</type>
47
36
<varname linkend="errorexception.props.severity">severity</varname>
37
+
<initializer>E_ERROR</initializer>
48
38
</fieldsynopsis>
49
39

50
40
<classsynopsisinfo role="comment">&InheritedProperties;</classsynopsisinfo>
51
-
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('exception.synopsis')/descendant::db:fieldsynopsis)" />
41
+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.exception')/db:partintro/db:section/db:classsynopsis/db:fieldsynopsis[preceding-sibling::db:classsynopsisinfo[1][@role='comment' and text()='&Properties;']]))">
42
+
<xi:fallback/>
43
+
</xi:include>
52
44

53
45
<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
54
-
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.errorexception')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[1])" />
55
-
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.errorexception')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])" />
46
+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.errorexception')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[@role='ErrorException'])">
47
+
<xi:fallback/>
48
+
</xi:include>
49
+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.errorexception')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='ErrorException'])">
50
+
<xi:fallback/>
51
+
</xi:include>
56
52

57
53
<classsynopsisinfo role="comment">&InheritedMethods;</classsynopsisinfo>
58
-
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.exception')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])" />
54
+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.exception')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='Exception'])">
55
+
<xi:fallback/>
56
+
</xi:include>
59
57
</classsynopsis>
60
58
<!-- }}} -->
61
59
...
...
@@ -79,33 +77,42 @@
79
77
&reftitle.examples;
80
78
<para>
81
79
<example xml:id="errorexception.example.error-handler"><!-- {{{ -->
82
-
<title>Use <function>set_error_handler</function> to change error messages into ErrorException.</title>
80
+
<title>Use <function>set_error_handler</function> to change error messages into ErrorException</title>
83
81
<programlisting role="php">
84
82
<![CDATA[
85
83
<?php
86
-
function exception_error_handler($severity, $message, $file, $line) {
87
-
if (!(error_reporting() & $severity)) {
88
-
// This error code is not included in error_reporting
84
+

85
+
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
86
+
if (!(error_reporting() & $errno)) {
87
+
// This error code is not included in error_reporting.
89
88
return;
90
89
}
91
-
throw new ErrorException($message, 0, $severity, $file, $line);
92
-
}
93
-
set_error_handler("exception_error_handler");
94
90

95
-
/* Trigger exception */
96
-
strpos();
91
+
if ($errno === E_DEPRECATED || $errno === E_USER_DEPRECATED) {
92
+
// Do not throw an Exception for deprecation warnings as new or unexpected
93
+
// deprecations would break the application.
94
+
return;
95
+
}
96
+

97
+
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
98
+
});
99
+

100
+
// Unserializing broken data triggers a warning which will be turned into an
101
+
// ErrorException by the error handler.
102
+
unserialize('broken data');
103
+

97
104
?>
98
105
]]>
99
106
</programlisting>
100
107
&example.outputs.similar;
101
108
<screen>
102
109
<![CDATA[
103
-
Fatal error: Uncaught exception 'ErrorException' with message 'strpos() expects at least 2 parameters, 0 given' in /home/bjori/tmp/ex.php:12
110
+
Fatal error: Uncaught ErrorException: unserialize(): Error at offset 0 of 11 bytes in test.php:16
104
111
Stack trace:
105
-
#0 [internal function]: exception_error_handler(2, 'strpos() expect...', '/home/bjori/php...', 12, Array)
106
-
#1 /home/bjori/php/cleandocs/test.php(12): strpos()
112
+
#0 [internal function]: {closure}(2, 'unserialize(): ...', 'test.php', 16)
113
+
#1 test.php(16): unserialize('broken data')
107
114
#2 {main}
108
-
thrown in /home/bjori/tmp/ex.php on line 12
115
+
thrown in test.php on line 16
109
116
]]>
110
117
</screen>
111
118
</example><!-- }}} -->
...
...
@@ -117,8 +124,7 @@ Stack trace:
117
124
&language.predefined.errorexception.construct;
118
125
&language.predefined.errorexception.getseverity;
119
126
120
-
</phpdoc:exceptionref>
121
-
127
+
</reference>
122
128
<!-- Keep this comment at the end of the file
123
129
Local variables:
124
130
mode: sgml
...
...
@@ -139,4 +145,3 @@ vim600: syn=xml fen fdm=syntax fdl=2 si
139
145
vim: et tw=78 syn=sgml
140
146
vi: ts=1 sw=1
141
147
-->
142
-

143
148