[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-cvs
Subject:    [DOC-CVS] svn: /phpdoc/en/trunk/language/oop5/ autoload.xml
From:       Richard_Quadling <rquadling () php ! net>
Date:       2009-11-25 11:00:11
Message-ID: svn-rquadling-1259146811-291300-586230153 () svn ! php ! net
[Download RAW message or body]

rquadling                                Wed, 25 Nov 2009 11:00:11 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=291300

Log:
Autoload and exceptions work. Mostly. Fix#50250

Bug: http://bugs.php.net/50250 (Open) Exceptions can be thrown and caught in an autoload function
      
Changed paths:
    U   phpdoc/en/trunk/language/oop5/autoload.xml

Modified: phpdoc/en/trunk/language/oop5/autoload.xml
===================================================================
--- phpdoc/en/trunk/language/oop5/autoload.xml	2009-11-25 10:41:56 UTC (rev 291299)
+++ phpdoc/en/trunk/language/oop5/autoload.xml	2009-11-25 11:00:11 UTC (rev 291300)
@@ -17,9 +17,13 @@
   </para>
   <note>
    <para>
-    Exceptions thrown in __autoload function cannot be caught in the
-    <link linkend="language.exceptions">catch</link> block and results in
-    a fatal error.
+    Prior to 5.3.0, exceptions thrown in the __autoload function could not be
+    caught in the <link linkend="language.exceptions">catch</link> block and
+    would result in a fatal error. From 5.3.0+ exceptions thrown in the
+    __autoload function can be caught in the <link linkend="language.exceptions">
+    catch</link> block, with 1 proviso. If throwing a custom exception, then
+    the custom exception class must be available. The __autoload function may
+    be used recursively to autoload the custom exception class.
    </para>
   </note>
   <note>
@@ -82,6 +86,66 @@
 ]]>
     </programlisting>
    </example>
+   <example>
+    <title>Autoloading with exception handling for 5.3.0+</title>
+    <para>
+     This example throws an exception and demonstrates the try/catch block.
+    </para>
+    <programlisting role="php">
+<![CDATA[
+<?php
+function __autoload($name) {
+    echo "Want to load $name.\n";
+    throw new Exception("Unable to load $name.");
+}
+
+try {
+    $obj = new NonLoadableClass();
+} catch (Exception $e) {
+    echo $e->getMessage(), "\n";
+}
+?>
+]]>
+    </programlisting>
+    &example.outputs;
+    <screen>
+<![CDATA[
+Want to load NonLoadableClass.
+Unable to load NonLoadableClass.
+]]>
+    </screen>
+   </example>
+   <example>
+    <title>Autoloading with exception handling for 5.3.0+ - Missing custom exception</title>
+    <para>
+     This example throws an exception for a non-loadable, custom exception.
+    </para>
+    <programlisting role="php">
+<![CDATA[
+<?php
+function __autoload($name) {
+    echo "Want to load $name.\n";
+    throw new MissingException("Unable to load $name.");
+}
+
+try {
+    $obj = new NonLoadableClass();
+} catch (Exception $e) {
+    echo $e->getMessage(), "\n";
+}
+?>
+]]>
+    </programlisting>
+    &example.outputs;
+    <screen>
+<![CDATA[
+Want to load NonLoadableClass.
+Want to load MissingException.
+
+Fatal error: Class 'MissingException' not found in testMissingException.php on line 4
+]]>
+    </screen>
+   </example>
   </para>

   <simplesect role="seealso">



-- 
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic