<?php
// Fiddle in response to StackOverflow question: https://stackoverflow.com/questions/69845122
// by HappyDog
// According to the PHP documentation, returning false from an output-buffer
// callback should result in the same result as returning the original input,
// but this fiddle shows that returning false actually breaks the buffer if it
// is 'cleaned'. The solution is to always return a string value.
//////////////////////////////
// CALLBACKS
// Returns false, which means 'use the buffer as supplied'.
function ReturnFalse($Buffer, $Phase) {
global $arrCallbacks;
$arrCallbacks[] = array($Buffer, $Phase);
return false;
}
// Returns the supplied buffer - result should be identical to returning false.
function ReturnBuffer($Buffer, $Phase) {
global $arrCallbacks;
$arrCallbacks[] = array($Buffer, $Phase);
return $Buffer;
}
//////////////////////////////
// TESTING CODE
foreach (array("ReturnFalse", "ReturnBuffer") as $Callback) {
$arrCallbacks = array();
print("== Testing " . $Callback . " ===\n");
ob_start($Callback);
print("First\n");
ob_clean();
print("Second\n");
ob_end_flush();
print("\n");
var_dump($arrCallbacks);
}