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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 15:01:33 2024 UTC