Doc #64193 [Opn->Nab]: Nested Exceptions with autoloader

From: Date: Sun, 17 Feb 2013 12:21:13 +0000
Subject: Doc #64193 [Opn->Nab]: Nested Exceptions with autoloader
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9529@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64193&edit=1 ID: 64193 Updated by: nikic@php.net Reported by: mostvotedplaya at gmail dot com Summary: Nested Exceptions with autoloader -Status: Open +Status: Not a bug Type: Documentation Problem Package: Dynamic loading Operating System: Centos 6.3 PHP Version: 5.4.11 Block user comment: N Private report: N New Comment: The Exception from the __autoload happens first and the code never reaches the throw of ReflectionException from the constructor. Previous Comments: ------------------------------------------------------------------------ [2013-02-12 03:04:26] mostvotedplaya at gmail dot com Description: ------------ --- From manual page: http://www.php.net/manual/en/language.exceptions.php --- I'm not sure if this is just a documentation bug or whether it goes further but in the documentation regarding nested exceptions it shows that they can be rethrown but in this case it doesn't appear that way, ReflectionClass uses __autoload to attempt to load the subject and once an exception arrives it just ignores the Reflection try block which for some people may be correct because ReflectionException has lower priority of Exception with it just being extended, but still the documentation should be updated to reflect this. Test script: --------------- <?php function __autoload( $f ) { $f = sprintf( '%s.php', $f ); if ( is_readable( $f ) ) { include $f; return; } throw new Exception( "Failed to autoload: $f" ); } try { try { $class = new ReflectionClass( "FooBar" ); if ( $class->isInstantiable() ) { return; } } catch ( ReflectionException $e ) { throw $e; } } catch ( Exception $e ) { echo '<pre>', print_r( $e, true ), '</pre>'; } Expected result: ---------------- ReflectionException Object ( [message:protected] => Class FooBar does not exist [string:Exception:private] => [code:protected] => -1 [file:protected] => /home/.../public_html/Reflection.php [line:protected] => 25 [trace:Exception:private] => Array ( [0] => Array ( [file] => /home/.../public_html/Reflection.php [line] => 25 [function] => __construct [class] => ReflectionClass [type] => -> [args] => Array ( [0] => FooBar ) ) ) [previous:Exception:private] => ) Actual result: -------------- Exception Object ( [message:protected] => Failed to autoload: FooBar.php [string:Exception:private] => [code:protected] => 0 [file:protected] => /home/.../public_html/Reflection.php [line:protected] => 18 [trace:Exception:private] => Array ( [0] => Array ( [function] => __autoload [args] => Array ( [0] => FooBar ) ) [1] => Array ( [file] => /home/.../public_html/Reflection.php [line] => 25 [function] => __construct [class] => ReflectionClass [type] => -> [args] => Array ( [0] => FooBar ) ) ) [previous:Exception:private] => ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64193&edit=1

« previous php.doc.bugs (#9529) next »