svn: /phpdoc/en/trunk/appendices/migration70/incompatible/ error-handling.xml
| From: | Adam Harvey | Date: | Mon, 11 Jan 2016 20:24:39 +0000 |
| Subject: | svn: /phpdoc/en/trunk/appendices/migration70/incompatible/ error-handling.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13972@lists.php.net to get a copy of this message | ||
aharvey Mon, 11 Jan 2016 20:24:39 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=338464
Log:
Be more explicit about set_exception_handler() breakage in PHP 7.
Changed paths:
U phpdoc/en/trunk/appendices/migration70/incompatible/error-handling.xml
Modified: phpdoc/en/trunk/appendices/migration70/incompatible/error-handling.xml
===================================================================
--- phpdoc/en/trunk/appendices/migration70/incompatible/error-handling.xml 2016-01-11 15:29:32 UTC
(rev 338463)
+++ phpdoc/en/trunk/appendices/migration70/incompatible/error-handling.xml 2016-01-11 20:24:39 UTC
(rev 338464)
@@ -24,6 +24,46 @@
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>