ID:               37829
 Updated by:       [EMAIL PROTECTED]
 Reported By:      e at osterman dot com
-Status:           Closed
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Debian
 PHP Version:      5.1.4


Previous Comments:
------------------------------------------------------------------------

[2006-06-16 22:38:22] e at osterman dot com

Please ignore this bug report. My code example is not correct as
re-assigning a variable does not in any way change the scope. I'll
resubmit a better example.

------------------------------------------------------------------------

[2006-06-16 21:00:10] e at osterman dot com

Description:
------------
This is either a bug in PHP, or an undocumented consequence of the
language's design -- either of which should be addressed.

If you want to have an object set an error handler to a method in
itself, such that when the object passes out of scope or gets
destroyed, the __destruct method is called (and previous error handler
restored), you cannot do it. The __destruct method is not called until
program termination.

It appears that by setting the error handler to $this->method, causes
$this to become copied rather than referenced. Using Array( &$this,
'method' ) versus Array( $this, 'method' ) has no effect on the outcome
-- the problem is "problem" is the same.

It's kind'a like creating a scope wormhole, I know, but the
documentation doesn't say it's not allowed! :)

Reproduce code:
---------------
class TestErrorHandler
{
    public function __construct()
    {
        print "construct\n";
        set_error_handler( Array( $this, 'handler') );
    }
    public function __destruct()
    {
        print "destruct\n";
        restore_error_handler();
    }
    public function handler()
    {
        print "handled\n";
    }

}

$foo = new TestErrorHandler();
$foo = new TestErrorHandler();

print "done.\n";



Expected result:
----------------
construct
destruct
construct
done.
destruct


Actual result:
--------------
construct
construct
done.
destruct
destruct



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=37829&edit=1

Reply via email to