ID: 22713 User updated by: public at asd-group dot com Reported By: public at asd-group dot com Status: Analyzed -Bug Type: Documentation problem +Bug Type: Output Control Operating System: Windows XP PHP Version: 4.3.2-RC New Comment:
Anyone looking at this problem - there is no workaround to this, so a fix is needed? Previous Comments: ------------------------------------------------------------------------ [2003-03-17 20:46:48] public at asd-group dot com I'm not sure how this just became a documentation problem. Sure, the recent manuals are incomplete/wrong with respect to ob_start, and that should be corrected. And regarding the chunk size parameter, I can tell you from actual testing and feedback from someone who knows the PHP source code (see http://www.zend.com/phorum/read.php?num=3&id=23814&loc=0&thread=23814) that it *DOES* cause the output callback to be called *ONCE* for each output statement, whether it is just one character (echo "1") or many (echo "A very,very,.....very,very long string"). That doesnt sound like setting a chunk size of 2 to me (assuming that means that the output buffer is flushed in chunks of 2 characters - without the correct info in the manual its hard to know). However, in any event, if the output callback instructs PHP to ignore the output text (by returning "") then headers should not be flushed and headers_sent() should continue to return FALSE. In a much larger application (too large to post), where I first saw this, there's an an additional curiosity. With output being captured and 'thrown away' by the output callback in this manner, the first 'echo' statement causes headers_sent() to return true, yet the code later does header() calls to set cookies, and these do not fail with a 'headers already sent' type of message (and the cookies get sent). I hoped to reproduce this within the little code snippet above, but that does fail with the expeced message if a call to header() is made after the first echo statement. Please could you recategorise this to a code issue. ------------------------------------------------------------------------ [2003-03-17 20:08:32] [EMAIL PROTECTED] Here's the proto for ob_start(): proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) The 2nd parameter determines the chunk size..not how many times the callback is called. ------------------------------------------------------------------------ [2003-03-17 13:58:03] public at asd-group dot com Hmm I did read and follow the notes, and the following sample script is easily extacted from my description. 4.3.2 made no difference. <?php $Html = Array(); // Output buffering callback - just buffers text and returns "" to PHP (telling it to ignore output) function PhpOutputCb ($txt) { global $Html; if ($txt != "") {$Html[] = $txt;} return ""; } // Install output buffering callback, called on each output statement (due to second parameter) // ISSUE: Second parameter should be documented ob_start('PhpOutputCb', 2); $t = "<pre>Before first output statement, headers_sent() = " . (int) headers_sent() . " </pre>\n"; echo "<html>\n". "<head>\n". "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">\n". "<meta http-equiv=\"Content-Language\" content=\"en-us\">\n". "<title>Bug1</title>\n". "</head>\n". "<body>\n". $t . "\n"; // ISSUE: Why does headers_sent() now return true, even though headers should not have been sent (as no output actually sent) echo "<pre>After first output statement, headers_sent() = " . (int) headers_sent() . " </pre>\n"; echo "</body>\n". "</html>\n"; // QUESTION: If commented-in, this exit() call causes PhpOutputCb to be called with "" text - why ?? //exit(); // Turn off output buffering and physically output text which our callback buffered ob_end_clean(); foreach ($Html as $key => $val) { echo $val; } ?> ------------------------------------------------------------------------ [2003-03-15 09:46:51] [EMAIL PROTECTED] Did you read the 'How to report' page at all? Did you try the latest stable snapshot from http://snaps.php.net yet? We're about to release 4.3.2 soon, so you really should test it. But most important: Add a short example script which clearly shows the problem. ------------------------------------------------------------------------ [2003-03-14 21:28:01] public at asd-group dot com What information do you want - I can't think of anything else that might be relevant ??? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/22713 -- Edit this bug report at http://bugs.php.net/?id=22713&edit=1