php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67902 Callback in ob not run
Submitted: 2014-08-25 13:49 UTC Modified: 2014-11-19 09:00 UTC
From: a dot vreugdenhil at amsio dot com Assigned:
Status: Wont fix Package: Output Control
PHP Version: 5.5.16 OS: CentOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
17 - 2 = ?
Subscribe to this entry?

 
 [2014-08-25 13:49 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-19 09:00 UTC] mike@php.net
-Status: Open +Status: Wont fix
 [2014-11-19 09:00 UTC] mike@php.net
Chicken and egg problem, sorry, something has to be done first.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC