php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #24346 ob_start wrongly optimized out when no callback specified
Submitted: 2003-06-26 09:33 UTC Modified: 2003-08-03 20:11 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: pitrou at free dot fr Assigned: davey (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.3.2 OS: Linux
Private report: No CVE-ID: None
 [2003-06-26 09:33 UTC] pitrou at free dot fr
Description:
------------
Newly with PHP 4.3.2, calls to ob_start with an empty handler (i.e. ob_start("")) seem to be optimized out and ignored.

This causes two problems :
- ob_start("") can be useful if you prefer to process the
  contents manually by using ob_get_contents() and then
  ob_end_clean()
- nesting of output buffers is broken, because the ob_end()
  call corresponding to ob_start("") is still taken (which
  can totally break the page if your ob_start("") is nested
  inside an ob_start("ob_gzhandler")...)


Reproduce code:
---------------
** This one doesn't work (second statement is eaten out) :

<?php
                                                                                                           
ob_start("ob_gzhandler");
ob_start("");
echo "first echo<p>";
ob_end_flush();
echo "second echo<p>";
ob_end_flush();
?>

** This one works (both statements are printed) :

<?php
                                                                                                           
function foo($x) { return $x; }
                                                                                                           
ob_start("ob_gzhandler");
ob_start("foo");
echo "first echo<p>";
ob_end_flush();
echo "second echo<p>";
ob_end_flush();
?>



Expected result:
----------------
Both programs should have the same result (i.e. print both statements on screen).


Actual result:
--------------
The program which calls ob_start with an empty handler fails to display the second statement. In the other program, we circumvent this bug by using a dummy handler, which causes it to work properly.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-26 09:38 UTC] derick@php.net
You should use NO parameter if you don't want a handler. PHP 4.3.2 correctly returns FALSE in this case.
 [2003-06-26 10:15 UTC] pitrou at free dot fr
Ok, then there's a compatibility problem (it used to work before).

Also the documentation is bogus too:
http://www.php.net/manual/en/function.ob-start.php

It doesn't mention the return value, the return type is
even supposed to be "void". How can I know I'm supposed to
check the return value ?

In the end I think a bad callback parameter to ob_start is enough to print an error message on screen (just as calling a function which doesn't exist prints an error message on screen).

Thanks for the reply.
 [2003-06-27 04:45 UTC] derick@php.net
It's indeed a change, but still, it's right as it is now. I'm changing this to a doc problem:
1. the return value is not documented
2. this function can also be used with the array() syntax to call methods of an object.

 [2003-06-30 03:31 UTC] derick@php.net
Point 1 has been documented now, assigning to philip as he's working on point 2.
 [2003-06-30 09:26 UTC] philip@php.net
Davey is actually the one working on this :)  Assigned->Davey
 [2003-08-03 20:11 UTC] et@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

Callbacks are now documented properly in http://de3.php.net/manual/en/language.pseudo-types.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 18:01:28 2024 UTC