Bug #67902 [Opn->Wfx]: Callback in ob not run
| From: | mike@php.net | Date: | Wed, 19 Nov 2014 09:00:15 +0000 |
| Subject: | Bug #67902 [Opn->Wfx]: Callback in ob not run | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188670@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67902&edit=1
ID: 67902
Updated by: mike@php.net
Reported by: a dot vreugdenhil at amsio dot com
Summary: Callback in ob not run
-Status: Open
+Status: Wont fix
Type: Bug
Package: Output Control
Operating System: CentOS
PHP Version: 5.5.16
Block user comment: N
Private report: N
New Comment:
Chicken and egg problem, sorry, something has to be done first.
Previous Comments:
------------------------------------------------------------------------
[2014-08-25 13:49:03] a dot vreugdenhil at amsio dot com
Description:
------------
Some (dirty) legacy code broke when upgrading to php 5.5.* from 5.3.*.
We pinpointed the problem to this:
Aparrently garbage collection removes stuff from the $GLOBALS superglobal before any open output
buffers are being flushed.
Prerequisites for the issue to occur:
1) using ob_start with a callback, and having it unended at the end of the script
2) the callback uses an object that's only referenced in the superglobal $GLOBALS
Apparently PHP removes the object earlier if it's only reference is in the $GLOBALS. If not,
nothing's wrong.
I know prettier code would never have encountered this problem, but since working old code stopped
working I'd call it a backwards incompatibility at the least.
Test script:
---------------
<?php
class test{
public $instance = null;
public $test = 'Hi, I\'m test';
}
$GLOBALS['test'] = new test();
function little_callback( $buffer ){
return $GLOBALS['test']->test;
}
ob_start( 'little_callback' );
echo "hello I'm in the buffer. You'll never see me because the callback replaces
me.";
// Enable this to make it work by creating a reference to the object
// $GLOBALS['test']->instance = $GLOBALS['test'];
// Enable this to make it work by flushing before the script ends so garbage collection doesn't
beat the output buffer to it
// ob_end_flush
?>
Expected result:
----------------
Hi, I'm test
Actual result:
--------------
Empty page.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67902&edit=1