php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31816 set_exception_handler() does not work for __autoload()
Submitted: 2005-02-02 15:54 UTC Modified: 2005-02-02 16:38 UTC
From: mandersm at student dot ethz dot ch Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.3 OS: Fedora (version n/a)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mandersm at student dot ethz dot ch
New email:
PHP Version: OS:

 

 [2005-02-02 15:54 UTC] mandersm at student dot ethz dot ch
Description:
------------
When an exception gets thrown in __autoload() my custom error handler is ignored and a PHP uncaught exception fatal error is displayed instead. Additionally the occuring fatal error message is not as nice as a regular uncaught exception error would be (no trace).

This bug *seems* to be related to http://bugs.php.net/bug.php?id=26591&edit=2 . I am still reporting it, since it still occurs with the latest snapshot version (20050202133, today 13:30) and is reproduced differently.

My config line:

'./configure' '--with-xslt' '--enable-sockets' '--with-apxs2=/usr/local/apache2/bin/apxs' '--enable-fastcgi' '--with-libxml' '--with-openssl' '--enable-ftp' '--with-gd' '--with-pgsql=/usr/local/pgsql' '--with-zlib-dir=/usr/lib/' '--disable-cgi' '--disable-magic-quotes' '--with-jpeg-dir=/usr/lib/' '--with-dom' '--with-dom-xslt' '--with-mysql=/usr/local/mysql-standard-4.0.23-pc-linux-i686'

No other special changes have been made. XDebug and APC are installed but *not* enabled in my php.ini.

Reproduce code:
---------------
<?php
function my_handler($e) {
	echo 'My custom Handler: '.$e->getMessage().'<br/>';
}

function regular_function() {
	throw new Exception('Regular function exception!');
}

function __autoload($class_name) {
	throw new Exception('__autoload function exception!');
}

set_exception_handler('my_handler');

/* attempt 1: */ regular_function();
/* attempt 2: */ $test = new Test(); // invoking __autoload()
?>

Expected result:
----------------
attempt 1: 'My custom Handler: Regular function exception!'
attempt 2: 'My custom Handler: __autoload function exception!'

Actual result:
--------------
attempt 1: 'My custom Handler: Regular function exception!'
attempt 2: 'Fatal error: Function __autoload(Test) threw an exception of type 'Exception' in /home/smartloader/htdocs/proof.php on line 22'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-02 16:03 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

fatal errors can not be caught by your own error handler - no bug here.
 [2005-02-02 16:25 UTC] mandersm at student dot ethz dot ch
Hi Derrick,

I know that. Why is a thrown exception in __autoload() or one that raises through it fatal? Why can't it raise like any other exception?

I guess this is not possible due to the special nature of the __autoload() hook. Nevertheless I think it's a bug (missing feature, if you want), since at the moment any exceptions thrown in code invoked by __autoload() must be caught in __autoload() to prevent a fatal error. I think this narrows the possibilities of creative users.

In my special case __autoload() includes files that produce warnings (i.e. deprecated 'var'). Additionally I wrote an error handler which throws exceptions rather than displaying the error.

Result: Thrown exception causes fatal error in __autoload, which then again throws an error and makes php crash. I haven't completely analyzed this behaviour yet though.

Please reconsider this matter.
 [2005-02-02 16:38 UTC] derick@php.net
Please search the bugreport, this was submitted before a couple of times, and denied too.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 14:01:28 2024 UTC