Jump to content

Throwing exception in __autoload();


Mchl

Recommended Posts

Manual says:

 

Note: Exceptions thrown in __autoload function cannot be caught in the catch block and results in a fatal error.

 

However when I run this code:

 

<?php
function __autoload($className) {
  if(file_exists("/classes/$className.class.php")) {  
    require_once("/classes/$className.class.php"); 
  } else {
throw new Exception("File /classes/$className.class.php does not exist"); 
  }

}

try {
$foo = new foo();
} catch(Exception $e) {
echo 'Exception caught:'.PHP_EOL;
echo $e->getMessage();
}

 

no fatal error occurs. Exception is handled as usual. I am doing this in 5.3 right now, but IIRC this was also a case in 5.2

Link to comment
Share on other sites

I think (my memory isn't what it used to be) this might have been "fixed" for 5.3.0... I'll take a look-see for more info.

 

P.S. Yep looks like 5.2 still suffers (just tried 5.2.11) and 5.3 (tested on 5.3.0) works as your post says.  If that's the case, the note on the manual page will get amended.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.