Edit report at https://bugs.php.net/bug.php?id=62437&edit=1
ID: 62437 Comment by: Sjon at hortensius dot net Reported by: tero dot tasanen at gmail dot com Summary: Strange behavior with global variables (objects) in ob_start() output callback Status: Open Type: Bug Package: Output Control Operating System: Linux 64bit PHP Version: 5.3.14 Block user comment: N Private report: N New Comment: Contrary to what tony2001 says in #40604, this was actually working fine until it was broken in 5.2 http://3v4l.org/SUUkK The reason that http://3v4l.org/pZ2PP works might be explained to the second reference to the same object which could prevent destruction, but that would then actually be a bug too (since it indicates a memory-leak). Previous Comments: ------------------------------------------------------------------------ [2012-06-28 11:56:12] tero dot tasanen at gmail dot com Description: ------------ Global variables in output buffering seem to work in very strange way. don't know actually if this has anything to do with output buffering callback but see the test case attached to reproduce this. And the strangest thing is that if you uncomment the last line the script works as expected! After some searching I found two similar bug reports (#40604, #44840) and the comments indicate that this is expected behavior?! Not just that it seem really strange that all objects get destroyed before the output callback is called, but why does the use of the $test variable in the end of the script change this behavior? This really does not make any sense! Test script: --------------- <? function output($buffer) { global $object; return $buffer . $object->bar; } ob_start('output'); $object = new stdClass(); $object->bar = "bar"; echo "foo "; // $test = $object; Expected result: ---------------- foo bar Actual result: -------------- PHP Notice: Trying to get property of non-object in /home/ttasanen/test.php on line 5 PHP Stack trace: PHP 1. output() /home/ttasanen/test.php:0 foo ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62437&edit=1