|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-11-07 12:03 UTC] vrana@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 31 23:00:01 2025 UTC |
Description: ------------ The description of the "output_callback" parameter in the doc for ob_start() states that: "The function will be called when ob_end_flush() is called, or when the output buffer is flushed to the browser at the end of the request." The testcase below shows 3 undocumented cases where the callback is invoked: - when the output buffer is flushed with ob_flush() - when the output buffer is cleaned with ob_clean() - when the output buffer is cleaned with ob_end_clean(). This could be indicated by adapting the description as follows: "The callback function will be invoked when the output buffer is flushed explicitly (using ob_flush() or ob_end_flush()), when it is flushed implicitly at the end of the request, or when it is cleaned (using ob_clean() or ob_end_clean()). In the case where the buffer is cleaned, the callback's return value is ignored." Reproduce code: --------------- <?php $a = ''; function output_handler($buffer, $mode) { global $a; static $i=0; $i++; $a .= "\n-->$i: In output_handler($buffer, $mode)"; return "Hello"; } echo "About to start buffer.\n"; ob_start('output_handler'); echo "About to call 'ob_flush()'"; ob_flush(); echo "About to call 'ob_clean()'"; ob_clean(); echo "About to call 'ob_end_clean()'"; ob_end_clean(); echo "\nEnded buffer.\n"; echo "\n\nShow when the callback was really invoked:"; echo $a; ?> Expected result: ---------------- N/A Actual result: -------------- About to start buffer. Hello Ended buffer. Show when the callback was really invoked: -->1: In output_handler(About to call 'ob_flush()', 3) -->2: In output_handler(About to call 'ob_clean()', 2) -->3: In output_handler(About to call 'ob_end_clean()', 4)