php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38387 Calling set_error_handler from constructor segfaults apache
Submitted: 2006-08-08 20:37 UTC Modified: 2006-08-09 08:32 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: trivoallan at clever-age dot com Assigned:
Status: Not a bug Package: Apache2 related
PHP Version: 5.1.4 OS: GNU/Linux (ubuntu dapper)
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: trivoallan at clever-age dot com
New email:
PHP Version: OS:

 

 [2006-08-08 20:37 UTC] trivoallan at clever-age dot com
Description:
------------
Apache version : 2.0.55

Calling set_error_handler from a class constructor makes apache crash.

Calling the function from other methods works without problems.

I've run accross #24708, and the problem does not come from there.

Reproduce code:
---------------
class cbJob
{
  public function __construct($id_ressource = null, $action_name = null)
  {
    set_error_handler(array($this, 'handleError'));
  }

  public function __destruct()
  {
    restore_error_handler();
  }
}

Expected result:
----------------
Error handler is cbJob::handleError()

Actual result:
--------------
[Tue Aug 08 22:09:49 2006] [notice] child pid 6876 exit signal Segmentation fault (11)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-08 20:48 UTC] judas dot iscariote at gmail dot com
what code your handleError method have ?

works perfectly fine in current 5_2 CVS... provide complete code please ;-)
 [2006-08-08 21:04 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

Can't reproduce.
 [2006-08-08 21:52 UTC] trivoallan at clever-age dot com
I found the source of the problem while reviewing the handleError method code (thanks for the pointer :).

There was a missing break in the switch statement.

Should it segfault anyway ?

Here's the uncorrected code for the handleError method : 

  function handleRuntimeError($errno, $errstr, $errfile = null, $errline = null, $errcontext = array() )
  {

    $error_types = array (
       E_ERROR              => 'Error',
       E_WARNING            => 'Warning',
       E_PARSE              => 'Parsing Error',
       E_NOTICE             => 'Notice',
       E_CORE_ERROR         => 'Core Error',
       E_CORE_WARNING       => 'Core Warning',
       E_COMPILE_ERROR      => 'Compile Error',
       E_COMPILE_WARNING    => 'Compile Warning',
       E_USER_ERROR         => 'User Error',
       E_USER_WARNING       => 'User Warning',
       E_USER_NOTICE        => 'User Notice',
       E_STRICT             => 'Runtime Notice',
       E_RECOVERABLE_ERRROR => 'Catchable Fatal Error'
    );

    $msg = sprintf('%s : "%s" occured in %s on line %d',
                   $error_types[$errno], $errstr, $errfile, $errline);

    switch($errno)
    {
      // A notice cannot fail the job
      case E_NOTICE:
        $this->setFailureMessage($msg);
      default:
        $this->errorOccured($msg, $this->getMaxTries());
    }
  }
 [2006-08-08 22:01 UTC] judas dot iscariote at gmail dot com
again, need **complete** reproduce code ..

WTH the setFailureMessage() and errorOccured() methods do eh ?
 [2006-08-08 22:22 UTC] trivoallan at clever-age dot com
bugs.php.net says : "Please do not SPAM our bug system."

so here's a link to the code : http://hashphp.org/pastebin.php?pid=8014
 [2006-08-09 07:52 UTC] mike@php.net
Sorry, I didn't even look further require_once.
 [2006-08-09 08:32 UTC] tony2001@php.net
1) Please try latest snapshot. http://snaps.php.net/php5.2-latest.tar.gz
2) After that, if you are still able to reproduce it, please provide a SHORT (max. 20 lines long) and COMPLETE (without any includes of non-existent files etc.) reproduce script.
Until then -> bogus.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 01:01:33 2025 UTC