#37829 [NEW]: set_error_handler used on a $this object causes unexpected result
| From: | e at osterman dot com | Date: | Fri, 16 Jun 2006 21:00:11 +0000 |
| Subject: | #37829 [NEW]: set_error_handler used on a $this object causes unexpected result | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-98422@lists.php.net to get a copy of this message | ||
From: e at osterman dot com
Operating system: Debian
PHP version: 5.1.4
PHP Bug Type: Class/Object related
Bug description: set_error_handler used on a $this object causes unexpected result
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 bug report at http://bugs.php.net/?id=37829&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37829&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37829&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37829&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37829&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=37829&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37829&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37829&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37829&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37829&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37829&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=37829&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=37829&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37829&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37829&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37829&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37829&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37829&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37829&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37829&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37829&r=mysqlcfg