php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61272 ob_start callback get passed empty string
Submitted: 2012-03-04 10:53 UTC Modified: 2012-11-27 09:11 UTC
Votes:18
Avg. Score:4.7 ± 0.7
Reproduced:17 of 17 (100.0%)
Same Version:12 (70.6%)
Same OS:5 (29.4%)
From: peacech at gmail dot com Assigned: mike (profile)
Status: Closed Package: Output Control
PHP Version: 5.4.0 OS: Arch 32 bit
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: peacech at gmail dot com
New email:
PHP Version: OS:

 

 [2012-03-04 10:53 UTC] peacech at gmail dot com
Description:
------------
Running test script below with PHP 5.4 outputs

""

Running test script below with PHP 5.3 outputs

"hello"

Test script:
---------------
<?php

$buffer = -1;
function callback($output)
{
	global $buffer;
	$buffer = $output;
	return $output;
}

ob_start('callback');
echo 'hello';
ob_get_clean();

var_dump($buffer);

Expected result:
----------------
"hello"

Actual result:
--------------
""

Patches

pass-cleaned-output-to-callback (last revision 2012-06-08 07:51 UTC by casper at langemeijer dot eu)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-05 11:23 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2012-03-05 11:23 UTC] mike@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

You should append $output to $buffer.
 [2012-03-05 14:43 UTC] peacech at gmail dot com
Unless ob_start callback specification has changed that for ob_clean/ob_end_clean, the output is discarded before calling the callback, then this is a bug. And I have scan the PHP 5.4 changelog and couldn't find anything mentioning this change.

So let me help by showing where the problem is

In line 1226 of output.c in the distributed PHP 5.4.0 source,

if (flags & PHP_OUTPUT_POP_DISCARD) {
    context.op |= PHP_OUTPUT_HANDLER_CLEAN;
    orphan->buffer.used = 0;
}
php_output_handler_op(orphan, &context);

orphan->buffer.used should not be set to 0 before calling the callback, otherwise the callback will be called with empty buffer.

And likewise in line 300 in php_output_clean

So, no, it isn't about appending $output to $buffer.
 [2012-05-18 10:04 UTC] patrick at procurios dot nl
We are having the same problem and it keeps us from migrating to 5.4. Could you please fix it?
 [2012-06-08 08:03 UTC] casper at langemeijer dot eu
Mike, I've dug a bit deeper into this problem, and must conclude that this 
really is a bug, or at least a change of behaviour.

I think test tests/output/ob_017.phpt is faulty too. I corrected bot output.c 
and the test in the patch I supplied.

In PHP 5.3 the callback function is called with the contents of the output 
buffer when ob_clean or ob_end_clean is called. The output will be fed to the 
callback function, but is erased right after that call.

After your output buffering rewrite the output buffer is cleaned before the 
callback is called.

I see no valid reason for a functional change. You're supplying the callback 
with a flag so that if needed the callback function could do this itself if 
needed.
 [2012-06-18 15:20 UTC] langemeijer@php.net
-Status: Not a bug +Status: Re-Opened
 [2012-07-10 08:59 UTC] dragon829 at gmail dot com
We have the same problem in 5.4.4,and it hasn't reproduced in 5.3.14 .
 [2012-08-21 11:17 UTC] a dot vi at laposte dot net
Same problem here with PHP5.4.6. I've had to patch my application and use:
ob_end_flush();
ob_clean();
instead of:
ob_end_clean();

I really agree with Casper: if this is not a change of behavior, this is a bug. 
My application was working really fine with PHP5.3.8 but was broken with 
PHP5.4.6. So something has changed 

Kind regards
 [2012-08-23 08:42 UTC] a dot vi at laposte dot net
Hi again,

I have used casper's patch. Compilation worked fine and it's all cool now. 
Thanks Casper

Regards
 [2012-11-23 07:40 UTC] tdroenner at gmail dot com
When is a official fix for this available?
 [2012-11-23 08:51 UTC] laruence@php.net
-Assigned To: +Assigned To: mike
 [2012-11-27 09:11 UTC] mike@php.net
-Status: Re-Opened +Status: Assigned
 [2012-11-28 09:27 UTC] mike@php.net
-Status: Assigned +Status: Closed
 [2012-11-28 09:27 UTC] mike@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src.git;a=commit;h=575790e8427ea09cb76aed16ff776461367f2a3b
Log: fix bug #61272 ob_start callback get passed empty string
 [2012-11-28 09:27 UTC] mike@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src.git;a=commit;h=575790e8427ea09cb76aed16ff776461367f2a3b
Log: fix bug #61272 ob_start callback get passed empty string
 [2012-11-30 06:30 UTC] laruence@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src.git;a=commit;h=575790e8427ea09cb76aed16ff776461367f2a3b
Log: fix bug #61272 ob_start callback get passed empty string
 [2012-12-19 17:55 UTC] derick@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src.git;a=commit;h=575790e8427ea09cb76aed16ff776461367f2a3b
Log: fix bug #61272 ob_start callback get passed empty string
 [2014-10-07 23:21 UTC] stas@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=575790e8427ea09cb76aed16ff776461367f2a3b
Log: fix bug #61272 ob_start callback get passed empty string
 [2014-10-07 23:32 UTC] stas@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=575790e8427ea09cb76aed16ff776461367f2a3b
Log: fix bug #61272 ob_start callback get passed empty string
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC