php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36268 Object destructors called even after fatal errors
Submitted: 2006-02-02 21:44 UTC Modified: 2006-02-03 10:55 UTC
From: hartmut@php.net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.2 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hartmut@php.net
New email:
PHP Version: OS:

 

 [2006-02-02 21:44 UTC] hartmut@php.net
Description:
------------
I just ran into this in CodeGen_PECL, wondering why the script
terminated half-way without giving any message, a stripped down
reproducing example is added below.

Basicly the problem was that a fatal error occuerd (which can't
be caught by an error handler) but my output buffer redirection
code still kicked in, so swallowing the error message from the
still active output buffer

its rather strange that i could implement an error handler
for E_FATAL errors using destructors whereas error_handler()
and register_shutdown_function() can't be used for this

Reproduce code:
---------------
<?php

class ob
{
  private $filename;

  function __construct($filename) {
	$this->filename = $filename;
	ob_start();
  }

  function __destruct() 
  {
	file_put_contents($this->filename, ob_get_clean());
  }
}


$ob = new ob("ob.txt");

foo::bar();

?>

Expected result:
----------------
the error message

 "Fatal error: Class 'foo' not found in /home/hartmut/new/ob.php on line 22"

shown on the console after calling the script

Actual result:
--------------
the error message

 "Fatal error: Class 'foo' not found in /home/hartmut/new/ob.php on line 22"

goes to the "ob.txt" file, not the console, when calling this using CLI,
the destructor is obviously executed *after* error handling

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-03 10:55 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 19:01:31 2024 UTC