php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33792 set_error_handler() disable __destruct()
Submitted: 2005-07-21 02:06 UTC Modified: 2005-07-21 04:59 UTC
From: deadman_great at mail dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.3 OS: WinXP
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: deadman_great at mail dot ru
New email:
PHP Version: OS:

 

 [2005-07-21 02:06 UTC] deadman_great at mail dot ru
Description:
------------
__destruct() not called on unset() if one of methods used as callback for set_error_handler() function.

Reproduce code:
---------------
class Sample
{
function __construct() { set_error_hanlder(array(&$this,'OnError')); }
function __destruct () { echo '[DESTRUCT]'; }
function OnError ($a,$b,$c,$d) { echo 'Error'; }
}

$sample = new Sample();

echo '[BEFORE]';
unset($sample);
echo '[AFTER]';

Expected result:
----------------
[BEFORE][DESTRUCT][AFTER]

Actual result:
--------------
[BEFORE][AFTER][DESTRUCT]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-21 02:08 UTC] deadman_great at wlp dot ru
Change e-mail
 [2005-07-21 02:16 UTC] tony2001@php.net
Because usind set_error_handler() you create a reference to the object and unset() only decrements reference count by 1, so the destructor gets called at the end of request and not during unset() execution.
No bug here, it's expected.
 [2005-07-21 04:59 UTC] deadman_great at mail dot ru
It's expected, but difficult for developers. It will be good if I can make all dereferences inside destructor, but if I call restore_error_handler(), apache crashes.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 09:01:32 2025 UTC