php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #64977 ob_start() fails when passed default parameters
Submitted: 2013-06-05 20:03 UTC Modified: 2024-01-07 14:05 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: rewilliams at newtekemail dot com Assigned: girgias (profile)
Status: Closed Package: Output Control
PHP Version: 5.5.0RC2 OS:
Private report: No CVE-ID: None
 [2013-06-05 20:03 UTC] rewilliams at newtekemail dot com
Description:
------------
Calling ob_start() with explicit parameters that match the defaults (using null to 
get past the first one, as documented), the various functions to end output 
buffering generate notices, which are also added to the buffered content. For 
example, ob_get_clean() returns the following:

	ob_get_clean(): failed to discard buffer of default output handler [...]
	ob_get_clean(): failed to delete buffer of default output handler (0) in 
[...]

It looks like output is spit out just as though buffering were not enabled, *and* 
the buffer gets saved - albeit with the buffering-related notices mixed in.

Testing at <http://sandbox.onlinephpfunctions.com>, it appears the bug was 
introduced in 5.4 (it works in 5.3.23) and continues through the latest version of 
5.5.

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

ob_start(null, 0, true);
echo 'hello world';
$foo = ob_get_clean();

var_dump($foo)

?>

Expected result:
----------------
string(11) "hello world"


Actual result:
--------------
PHP Notice:  ob_get_clean(): failed to discard buffer of default output handler 
(0) in [...] on line 5
PHP Notice:  ob_get_clean(): failed to delete buffer of default output handler (0) 
in [...] on line 5
hello world
Notice: ob_get_clean(): failed to discard buffer of default output handler (0) in 
[...] on line 5

Notice: ob_get_clean(): failed to delete buffer of default output handler (0) in 
[...] on line 5
string(11) "hello world"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-06 08:20 UTC] ab@php.net
-Status: Open +Status: Analyzed
 [2013-06-06 08:20 UTC] ab@php.net
This is more like a documentation bug. There is a bunch of constants 
undocumented http://lxr.php.net/xref/PHP_5_4/main/output.c#204 . Also the third 
ob_start() argument can be not only true/false, you can pass various flags 
there. As such, if you change your first line

ob_start(null, 0, PHP_OUTPUT_HANDLER_REMOVABLE)

no warnings will be to see.

Please change this bug to be a documentation one. Or you could even fix the 
docs.
 [2013-08-06 03:15 UTC] kubo at iteman dot jp
> This is more like a documentation bug. There is a bunch of constants 
> undocumented http://lxr.php.net/xref/PHP_5_4/main/output.c#204 . Also the 
third 
> ob_start() argument can be not only true/false, you can pass various flags 
> there. As such, if you change your first line

> ob_start(null, 0, PHP_OUTPUT_HANDLER_REMOVABLE)

> no warnings will be to see.

It works. But the "del" entry for ob_get_status() is never set with the default 
value or the built-in constants on PHP 5.4. The "del" entry is always set on PHP 
5.3.
 [2013-08-06 06:39 UTC] mike@php.net
-Package: Scripting Engine problem +Package: Documentation problem
 [2013-08-06 06:39 UTC] mike@php.net
This is about correct. We missed to document the new flags parameter including 
available constants for 5.4+

So:
PHP_OUTPUT_HANDLER_REMOVABLE: whether ob_end_*() can be called
PHP_OUTPUT_HANDLER_CLEANABLE: whether ob_*_clean() can be called
PHP_OUTPUT_HANDLER_FLUSHABLE: whether ob_flush() can be called
PHP_OUTPUT_HANDLER_STDFLAGS: all above OR'ed together

On another note: the "del" status array element is never set in 5.4+, the flags 
entry will contain PHP_OUTPUT_HANDLER_REMOVABLE if it's deletable.
 [2013-08-08 06:12 UTC] masakielastic at gmail dot com
The following page also should be updated.

http://www.php.net/manual/en/outcontrol.constants.php

There is no description for PHP_OUTPUT_HANDLER_CLEANABLE, 
PHP_OUTPUT_HANDLER_DISABLED, PHP_OUTPUT_HANDLER_FLUSHABLE, 
PHP_OUTPUT_HANDLER_REMOVABLE, PHP_OUTPUT_HANDLER_STARTED, 
PHP_OUTPUT_HANDLER_STDFLAGS.

The list of all constants added in PHP 5.4 is found in the following instruction 
page.
http://www.php.net/manual/en/migration54.global-constants.php
 [2013-09-26 21:23 UTC] aharvey@php.net
Mike, what happens if you pass true as the "flags" parameter in 5.4+? It looks 
easier to ask you than figure out the code paths, honestly, and we need to cover 
the BC story somehow.
 [2013-09-27 08:05 UTC] mike@php.net
Duh, unfortunately pretty much the opposite:

bool(true) -> int(1) & ~0xf == 0

The first bits are reserved for the OB handler type (internal/user) and thus ignored, so flags end up as zero, which in turn means the handler is neither removeable, nor flushable, nor cleanable.

I suspect, I could have done better.
 [2013-09-27 18:44 UTC] aharvey@php.net
-Status: Analyzed +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2013-09-27 18:44 UTC] aharvey@php.net
We probably should have picked that up at the time. Whoops.

OK, I'll assign this to myself and figure out how to document it. Probably won't 
be today.
 [2013-10-01 18:35 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=331632
Log: Document the ob_start() changes in PHP 5.4.

Mostly fixes doc bug #64977 (ob_start() fails when passed default parameters).
 [2013-10-01 18:37 UTC] aharvey@php.net
OK, documentation is done except for the PHP_OUTPUT_BUFFER_STARTED and 
PHP_OUTPUT_BUFFER_DISABLED constants, mostly because I can't figure out how 
they're useful.

Mike, help please? :)
 [2014-11-19 09:31 UTC] mike@php.net
PHP_OUTPUT_HANDLER_STARTED just indicates that the handler has been called previously with PHP_OUTPUT_HANDLER_START set, so it would not get that flag again, unless it has also seen PHP_OUTPUT_HANDLER_FINAL in the meantime.

So:
handler(PHP_OUTPUT_HANDLER_START) => flags |= STARTED
handler(PHP_OUTPUT_HANDLER_FINAL) => flags ^= STARTED

PHP_OUTPUT_HANDLER_DISABLED: 
Internal output handlers can mark them self as disabled with php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_DISABLE), when they f.e. detect an error; see README.NEW-OUTPUT-API.
Also, when a call to an internal or userland handler fails, or the userland handler returns FALSE.
 [2014-11-19 12:14 UTC] mike@php.net
See also Doc Bug #62019
 [2017-01-28 12:24 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem -Package: Documentation problem +Package: Output Control
 [2017-10-24 07:18 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: aharvey +Assigned To:
 [2024-01-07 14:05 UTC] girgias@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: girgias
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 16:01:29 2024 UTC