#44840 [Opn->Bgs]: objects destroyed on callback functions

From: Date: Sat, 26 Apr 2008 19:17:07 +0000
Subject: #44840 [Opn->Bgs]: objects destroyed on callback functions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-124536@lists.php.net to get a copy of this message
ID: 44840 Updated by: jani@php.net Reported By: fabiovh at gmail dot com -Status: Open +Status: Bogus Bug Type: Output Control Operating System: RHEL5 PHP Version: 5.2.5 New Comment: This is expected behaviour. Object destructors are called before flushing the output buffers, so if your object has refcount == 1 (which is the case with $t2=$t1 commented out), $t1 is already destroyed when the callback is called. You do not see the error message, because the error happens in the function which flushes the buffer, so this is also expected. Previous Comments: ------------------------------------------------------------------------ [2008-04-26 10:53:43] fabiovh at gmail dot com Description: ------------ It is already filed as Bug #39693, but I did not find a way to reopen it or comment on it. I believe it has been marked as bogus in mistake, or at least with not enough pondering about the problem. I'm sure this wasn't the behavior in earlier versions of PHP 5, since my code just broke with the upgrade, exactly because objects are now destroyed, but it worked fine before. At least mentioning this new behavior in the docs (on ob_start) would be sensitive. But to me it's waaay weird that everything else works in those callback functions, except objects. I think it's pretty severe, since this change of behavior breaks compatibility and makes output buffer processing useless for OO applications. I had to change a lot of code - for the worse - to make it compatible. Reproduce code: --------------- <? ob_start('callback'); class Test { function method() { return 'cow'; } } $test = new Test(); function callback ($content) { global $test; return 'm:'.$test->method(); } ?> Expected result: ---------------- cow Actual result: -------------- [none] httpd: PHP Fatal error: Call to a member function method() on a non-object in (...).php on line 16 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44840&edit=1

« previous php.bugs (#124536) next »