|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-06-16 22:38 UTC] e at osterman dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 17:00:01 2025 UTC |
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