ID:               26193
 Updated by:       [EMAIL PROTECTED]
 Reported By:      acm at tweakers dot net
 Status:           Wont fix
 Bug Type:         Zend Engine 2 problem
 Operating System: *
 PHP Version:      5.0.0b2 (beta2)
 New Comment:

On http://de.php.net/manual/en/language.oop5.autoload.php a nice
workaround was posted:

The following might provide a good work-around for throwing exceptions
from the __autoload function when a file containing the correct class
doesn't exists.

function __autoload ($class_name) {
  $file = 'system/objects/' . $class_name . '.inc.php';
  if (!file_exists ($file)) {
   return eval ("class $class_name {" .
                 "  function $class_name () {" .
                 "    throw new Exception ();" .
                 "  }" .
                 "}");
  }
  require_once ($file);
}



Previous Comments:
------------------------------------------------------------------------

[2003-11-10 19:28:43] [EMAIL PROTECTED]

For internal reasons there is nothing else the executor can do, so
catching such an exception will leave the executot in an unstable
state. Hence there is no exception.

Only in case of class_exists() and exception would be possible. But i
don't think someone will find a good solution for that and goes
implementing it.

------------------------------------------------------------------------

[2003-11-10 17:17:43] acm at tweakers dot net

Description:
------------
When You try to implement some sort of class-loader, the
autoload-function is very usefull.
But as soon as you want the user-code to do something special when a
class isn't found, it'd be handy to throw out an exception, which the
user-code either can catch or ignore.

With the current beta2 that isn't possible as it seems.

Reproduce code:
---------------
<?
    function __autoload($class)
    {
        throw new Exception($class . " does not exist.");
    }

try
{
    $obj = new test(); // Where test is a non-existent class
}
catch(Exception $e)
{
    echo $e;
}
?>

Expected result:
----------------
Something like:
exception 'exception' with message 'test does not exist.' etc..

Actual result:
--------------
Fatal error: __autoload threw an exception in
/home/acm/public_html/kb/autoload.php on line 11


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=26193&edit=1

Reply via email to