#44840 [Bgs]: objects destroyed on callback functions

From: Date: Mon, 28 Apr 2008 08:20:30 +0000
Subject: #44840 [Bgs]: objects destroyed on callback functions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-124554@lists.php.net to get a copy of this message
ID: 44840 User updated by: fabiovh at gmail dot com Reported By: fabiovh at gmail dot com Status: Bogus Bug Type: Output Control Operating System: RHEL5 PHP Version: 5.2.5 New Comment: You just copied and pasted the other answer without considering my comments. Is this how the PHP community is? No mentioning of this important change in manual or changelog, just broken code when upgrading. Support for OO programming actually diminishing. Shame. Previous Comments: ------------------------------------------------------------------------ [2008-04-26 19:17:07] jani@php.net 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. ------------------------------------------------------------------------ [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 (#124554) next »