php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #64193 Nested Exceptions with autoloader
Submitted: 2013-02-12 03:04 UTC Modified: 2013-02-17 12:21 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mostvotedplaya at gmail dot com Assigned:
Status: Not a bug Package: Dynamic loading
PHP Version: 5.4.11 OS: Centos 6.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
3 + 27 = ?
Subscribe to this entry?

 
 [2013-02-12 03:04 UTC] 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] => 
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-17 12:21 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-02-17 12:21 UTC] nikic@php.net
The Exception from the __autoload happens first and the code never reaches the throw of ReflectionException from the constructor.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 21:01:29 2024 UTC