Ticket #162 (new defect)

Opened 2 years ago

Last modified 3 months ago

Error/Exception handler in class sometimes causes bogus errors.

Reported by: jazfresh Assigned to: somebody
Priority: minor Milestone: 0.9.5
Component: eAccelerator Version:
Keywords: Cc: hp@learnbit.com, silfreed@silfreed.net

Description

PHP allows you to set your own exception/error handler with the set_exception_handler and set_error_handler functions. Like most PHP functions that take callbacks as parameters, PHP allows you to pass in an array containing an object name and a method name, e.g.

set_error_handler(array('SomeClass?', 'someMethod'));

This will call the static function SomeClass::someMethod() whenever an error occurs.

However, eAccelerator sometimes fails to handle this correctly. The symptoms are errors like "Cannot find class 'SomeClass?'" occuring in seemingly bogus places, for example whenever a "var $foo;" is encountered in a class definition. This indicates that the "var $foo;" triggered an E_STRICT error (as it should), but the error handler was not found (even though SomeClass? has definitely been defined). If eAccelerator is disabled, the code works fine.

I could not reproduce this bug using a minimal example (otherwise I would have submitted it along with this report).

Change History

08/08/06 17:05:36 changed by jazfresh

Forgot to add - this occurs in 0.9.2 with PHP 5.0.4, and also in 0.9.4-beta2 with PHP 5.1.4.

08/08/06 17:24:09 changed by bart

Please try 0.9.5-rc1 (btw do you mean 0.9.5-beta2?)

08/09/06 11:20:46 changed by hp

  • cc set to hp@learnbit.com.

The problem does still exist in 0.9.5-rc1 on PHP 5.1.4.

08/09/06 11:29:52 changed by hp

By the way, the problem also arises when setting the error handler to a non-static function: set_error_handler(array(&$system, 'handlePhpError'));

08/22/06 09:15:33 changed by dmakovec

Just verified, the problem still exists with 0.9.5-rc1 on PHP 5.1.5.

I have a file, ErrorHandler?.class.php, that is require_once()'d from a master include file, defined as follows:

class ErrorHandler {
  static private $instance = null;

  static function instance() {
    if (!ErrorHandler::$instance) {
      ErrorHandler::$instance = new ErrorHandler();
    }
    return ErrorHandler::$instance;
  }

  private function __construct() {}

  /**
   * Callback to handle any errors dispatched by trigger_error routines
   */
  function handleError($errno, $errstr, $errfile, $errline, $errctx) {
    # Do something based on the error
    ...
  }
}
$eh = ErrorHandler::instance();

set_error_handler(array(&$eh, "handleError"));

Without eAccelerator, there's no problem. As soon as I enable eAccelerator, I get "Cannot find class 'ErrorHandler?'".

My workaround: Replace the last two lines with:

function ___handleError($errno, $errstr, $errfile, $errline, $errctx) {
  $eh = ErrorHandler::instance();
  $eh->handleError($errno, $errstr, $errfile, $errline, $errctx);
}

set_error_handler("___handleError");

08/25/06 13:52:40 changed by hans

  • milestone set to 0.9.6.

11/08/06 16:36:52 changed by bart

I've tried eaccelerator trunk with php 5.2 and 0.9.5 with php 5.1.5 and this piece of code:

{{{<?php class ErrorHandler? {

static private $instance = null;

static function instance() {

if (!ErrorHandler::$instance) {

ErrorHandler::$instance = new ErrorHandler?();

} return ErrorHandler::$instance;

}

private function construct() {}

/**

  • Callback to handle any errors dispatched by trigger_error routines */

function handleError($errno, $errstr, $errfile, $errline, $errctx) {

# Do something based on the error echo $errstr;

}

} $eh = ErrorHandler::instance();

set_error_handler(array(&$eh, "handleError"));

$bla = file_get_contents('blablabl');

?> }}}

08/19/07 19:55:59 changed by bart

I still haven't found a way to reproduce this problem. Are you still seeing this problem with current development versions? Does this problem occur when you keep eA enabled but disable it's optimizer?

11/06/07 22:40:39 changed by MaZderMind

I must admit to bart that in the current trunk-build (using VC++ 2005 under WinXP) the code above seems to work. We saw this problem when trying eAccelerator on our Quality Assurance machine at work with one of our Applications that uses the PEAR-Error-Handler in this way.

I will soon try a trunk-build on our CentOS-QA-Server and report about it. If this is fixed I'm happily awaiting the next stable to use on our live system. Unfortunately things seem to stuck a little (3 months since the last checkin), but i'm not out of hope...

11/13/07 01:15:58 changed by ian_f

  • milestone changed from 0.9.6 to 0.9.5.

I use eAccelerator 0.9.5.2 on PHP 5.2 and I have the same problem. It seems to happen when several PHP files are involved.

Here's some code I've wrote that produce the bug. It's splitted into 3 files because everything works fine if all the code is in the same file.

err_handler.php :

<?php
set_error_handler(array('ErrorHandler', 'handle_error'));

class ErrorHandler
{
        static function handle_error($errno, $errstr)
        {
                // Error handling stuff
        }
}
?>

TestClass?.php :

<?php
class TestClass
{
        function instance()
        {
                // The line below raise an E_STRICT 
                // (should not be handled because error_reporting=E_ALL)
                $var =& new TestClass();
        }       
}   
?>

index.php :

<?php
require_once 'err_handler.php';
require_once 'TestClass.php';
?>

Opening "index.php" in my browser shows :

Fatal error: Class 'ErrorHandler' not found in TestClass.php on line 7

The error is trigger by the line "$var =& new TestClass?();". If I turn off eAccelerator, the scripts work fine.

Hope this helps !

01/14/08 17:05:05 changed by Eri

On SUSE 9.3 with php 5.2.5 i get the following results:

Trying dmakovec workaround: Segfault, no matter in how many files i split it. Trying what ian_f described: Fatal error. Just using a function: Works ;)

If i can help in any way please feel free to contact me.

04/07/08 21:19:21 changed by DougWarner

  • cc changed from hp@learnbit.com to hp@learnbit.com, silfreed@silfreed.net.