|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2007-07-25 10:35 UTC] nicolas dot grekas+php at gmail dot com
 Description:
------------
See code sample (tested with PHP 5.2.1)
Reproduce code:
---------------
<?php
error_reporting(E_ALL | E_STRICT);
set_error_handler('reportError');
function reportError($code, $message)
{
	return errorReporter::report($code, $message);
}
function __autoload($class)
{
	class errorReporter
	{
		static function report($code, $message) { echo $message, '<br />'; }
	}
}
// When uncommented, this triggers an E_NOTICE, so reportError() is called,
// which itself calls errorReporter::report(), which triggers __autoload(),
// which loads the errorReporter class, and everything is fine:
//unset($a);
//echo $a;
// This  triggers an E_STRICT, so things should be the same as above,
// exept that __autoload() is never called, so the errorReporter class is never loaded,
// so we end up with an E_FATAL... BUG
eval('
class A           { function toto(  ) {} }
class B extends A { function toto($a) {} }
');
Expected result:
----------------
Declaration of B::toto() should be compatible with that of A::toto()
Actual result:
--------------
Fatal error: Class 'errorReporter' not found in [...](35) : eval()'d code on line 3
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 05:00:02 2025 UTC | 
Of course it doesn't work for this exact error: It's caught during compile time. Only execute time errors can be caught with user error handler. Try change the eval'd code to following: eval(' class A { function toto( ) {} } A::toto(); '); This works fine..and it's also E_STRICT error..I made some tests, and found a workaround that prove that you are wrong: the problem is really that __autoload() is not called, and not that the error_handler is not called. In reportError() the before the return and it works, just add: class_exists('errorReporter', false) || __autoload('errorReporter'); and it works. This proves that the error handler is called. (btw, that's also why I added the "eval" thing in the example. Without the eval you would be right...)yes, with an include : replace the eval with include 'toto.php', where toto.php contains <?php class A { function toto( ) {} } class B extends A { function toto($a) {} } ?> this is how I hit the bug the first time