3v4l.org

run code in 300+ PHP versions simultaneously
<?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); }
Output for git.master, git.master_jit, rfc.property-hooks
== Testing ReturnFalse === Second array(1) { [0]=> array(2) { [0]=> string(6) "First " [1]=> int(3) } } == Testing ReturnBuffer === Second array(2) { [0]=> array(2) { [0]=> string(6) "First " [1]=> int(3) } [1]=> array(2) { [0]=> string(7) "Second " [1]=> int(8) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
72.93 ms | 401 KiB | 8 Q