|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42641 ob_start(): inconsistent behaviour with undefined callbacks
Submitted: 2007-09-12 09:15 UTC Modified: 2009-02-23 09:38 UTC
Avg. Score:2.2 ± 1.3
Reproduced:2 of 3 (66.7%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: robin_fernandes at uk dot ibm dot com Assigned: mike (profile)
Status: Wont fix Package: Output Control
PHP Version: 5.3CVS-2008-11-01 (not for 5.2!) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: robin_fernandes at uk dot ibm dot com
New email:
PHP Version: OS:


 [2007-09-12 09:15 UTC] robin_fernandes at uk dot ibm dot com
ob_start() can initialize multiple output buffers in a single call using a comma delimited list of output callbacks, as follows:
where function f() is a defined function.

However, behaviour when passing an undefined callback is inconsistent:
returns false and initializes no output buffers, whereas
returns true and initializes 2 output buffers with f as a callback.

Using arrays, the behaviour is consistent. The following both return false and initialize no output buffers:
  ob_start(array('non_existent', 'f'));
  ob_start(array('non_existent', 'f', 'f'));

Tested on Windows XP on PHP 5.2.5-dev (cli) (built: Sep 12 2007 04:04:36).

Reproduce code:
function f($str) {
  return $str;
function checkAndClean() {
  while (ob_get_level()>0) {
var_dump(ob_start(array('non_existent', 'f')));
var_dump(ob_start(array('non_existent', 'f', 'f')));
var_dump(ob_start('non_existent,f,f'));  //bug: expecting false with no output buffers. Actually returns true and initialises 2 output buffers.

Expected result:

Actual result:
    [0] => f
    [1] => f


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-12 11:17 UTC]
Let's start with the prototype for this function:

bool ob_start ( [callback $output_callback [, int $chunk_size [, bool $erase]]] )

The first parameter is "callback" type, so it expects either a string (function name) or array (object, method).

More information about "callback" pseudo-type:

I don't know where you got the idea that you can pass multiple callbacks in there. It's not said to work like that anywhere in the manual at least. :)

Please fix your example script accordingly (and tune up your display_errors / error_reporting levels..).
 [2007-09-12 14:06 UTC] robin_fernandes at uk dot ibm dot com

Thanks for your reply. As documentation isn't always complete/up to date, I looked at the implementation of ob_start() to understand its behaviour.

The code in the 5.2 version of php_ob_init() in output.c splits strings on ',' and attempts to process each part seaparately (line 485). For arrays, if a pair does not represent a method, a comment explicitly states "init all array elements recursively" (line 516).

The prototype in the 5.2 code currently looks like this:
bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]])

The following testcase shows this behaviour in action:

Regarding tuning up the error message display params, I'm currently using: error_reporting  = E_ALL | E_STRICT / display_errors = 1 . Would you expect see warnings/notices with my testcase?

I'll happily raise a documentation bug to ensure this is covered. Alternatively, perhaps the fact that this behaviour is available is itself a bug? Note that this is raised against php5 (not 6 where the output buffering implementation seems to be a bit different).
 [2007-09-13 09:22 UTC]
Yeah, now that I took a closer look I can see there's something like this implemented..I wonder when/why. :)

Please don't open documentation issue yet.
 [2007-09-13 19:05 UTC]
This undocumented behaviour does not exist in any way in HEAD any longer.  The implementation seemed questionable, as an array as parameter usually indicates a method callback.

 [2007-09-14 10:07 UTC] robin_fernandes at uk dot ibm dot com
OK. On this subject, I think I'm running into a few other output buffering issues which seem to be fixed in the php6 snaps. Some of these are illustrated by tests in HEAD that fail on php5 snaps, e.g. . Should I raise bugs against php5, or is there a plan to backport some output buffering code from HEAD to php5?
 [2007-09-18 12:28 UTC]
Mike, can you backport the stuff to PHP_5_3 once it's opened?
 [2008-11-02 13:01 UTC]
Mike, just commit it!
 [2009-02-23 09:38 UTC]
Patch for 5.3 has been declined.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Feb 27 15:01:32 2024 UTC