File: error-handling.xml

package info (click to toggle)
php-doc 20241205~git.dfcbb86%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 70,956 kB
  • sloc: xml: 968,269; php: 23,883; javascript: 671; sh: 177; makefile: 37
file content (169 lines) | stat: -rw-r--r-- 5,332 bytes parent folder | download
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<sect2 xml:id="migration70.incompatible.error-handling">
 <title>Changes to error and exception handling</title>

 <para>
  Many fatal and recoverable fatal errors have been converted to exceptions in
  PHP 7. These error exceptions inherit from the <classname>Error</classname>
  class, which itself implements the <classname>Throwable</classname>
  interface (the new base interface all exceptions inherit).
 </para>

 <para>
  This means that custom error handlers may no longer be triggered because
  exceptions may be thrown instead (causing new fatal errors for uncaught
  <classname>Error</classname> exceptions).
 </para>

 <para>
  A fuller description of how errors operate in PHP 7 can be found
  <link linkend="language.errors.php7">on the PHP 7 errors page</link>. This
  migration guide will merely enumerate the changes that affect backward
  compatibility.
 </para>

 <sect3 xml:id="migration70.incompatible.error-handling.set-exception-handler">
  <title>
   <function>set_exception_handler</function> is no longer guaranteed to
   receive <classname>Exception</classname> objects
  </title>

  <para>
   Code that implements an exception handler registered with
   <function>set_exception_handler</function> using a type declaration of
   <classname>Exception</classname> will cause a fatal error when an
   <classname>Error</classname> object is thrown.
  </para>

  <para>
   If the handler needs to work on both PHP 5 and 7, you should remove the
   type declaration from the handler, while code that is being migrated to
   work on PHP 7 exclusively can simply replace the
   <classname>Exception</classname> type declaration with
   <classname>Throwable</classname> instead.
  </para>

  <informalexample>
   <programlisting role="php">
<![CDATA[
<?php
// PHP 5 era code that will break.
function handler(Exception $e) { ... }
set_exception_handler('handler');

// PHP 5 and 7 compatible.
function handler($e) { ... }

// PHP 7 only.
function handler(Throwable $e) { ... }
?>
]]>
   </programlisting>
  </informalexample>
 </sect3>

 <sect3 xml:id="migration70.incompatible.error-handling.constructors">
  <title>Internal constructors always throw exceptions on failure</title>

  <para>
   Previously, some internal classes would return &null; or an unusable object
   when the constructor failed. All internal classes will now throw an
   <classname>Exception</classname> in this case in the same way that user
   classes already had to.
  </para>
 </sect3>

 <sect3 xml:id="migration70.incompatible.error-handling.parse">
  <title>Parse errors throw <classname>ParseError</classname></title>

  <para>
   Parser errors now throw a <classname>ParseError</classname> object. Error
   handling for <function>eval</function> should now include a &catch; block
   that can handle this error.
  </para>
 </sect3>

 <sect3 xml:id="migration70.incompatible.error-handling.strict">
  <title>E_STRICT notices severity changes</title>

  <para>
   All of the <constant>E_STRICT</constant> notices have been reclassified to
   other levels. <constant>E_STRICT</constant> constant is retained, so calls like
   <literal>error_reporting(E_ALL|E_STRICT)</literal> will not cause an error.
  </para>
  <para>
   <table>
    <title><constant>E_STRICT</constant> notices severity changes</title>
     <tgroup cols="2">
      <thead>
       <row>
        <entry>Situation</entry>
        <entry>New level/behaviour</entry>
       </row>
      </thead>
      <tbody>
       <row>
        <entry>Indexing by a resource</entry>
        <entry><constant>E_NOTICE</constant></entry>
       </row>
       <row>
        <entry>Abstract static methods</entry>
        <entry>Notice removed, triggers no error</entry>
       </row>
       <row>
        <entry>"Redefining" a constructor</entry>
        <entry>Notice removed, triggers no error</entry>
       </row>
       <row>
        <entry>Signature mismatch during inheritance</entry>
        <entry><constant>E_WARNING</constant></entry>
       </row>
       <row>
        <entry>Same (compatible) property in two used traits</entry>
        <entry>Notice removed, triggers no error</entry>
       </row>
       <row>
        <entry>Accessing static property non-statically</entry>
        <entry><constant>E_NOTICE</constant></entry>
       </row>
       <row>
        <entry>Only variables should be assigned by reference</entry>
        <entry><constant>E_NOTICE</constant></entry>
       </row>
       <row>
        <entry>Only variables should be passed by reference</entry>
        <entry><constant>E_NOTICE</constant></entry>
       </row>
       <row>
        <entry>Calling non-static methods statically</entry>
        <entry><constant>E_DEPRECATED</constant></entry>
       </row>
      </tbody>
     </tgroup>
    </table>
   </para>
 </sect3>
</sect2>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->