Skip to content

Instantly share code, notes, and snippets.

@codemedic
Forked from kemo/fix.diff
Created July 18, 2013 22:36
Show Gist options
  • Save codemedic/6033714 to your computer and use it in GitHub Desktop.
Save codemedic/6033714 to your computer and use it in GitHub Desktop.
diff --git a/system/core/Kohana.php b/system/core/Kohana.php
index 271f917..287c271 100644
--- a/system/core/Kohana.php
+++ b/system/core/Kohana.php
@@ -722,7 +722,7 @@ final class Kohana {
if (ob_get_level() >= self::$buffer_level)
{
// Set the close function
- $close = ($flush === TRUE) ? 'ob_end_flush' : 'ob_end_clean';
+ $close = ($flush === TRUE) ? 'ob_end_flush' : 'Kohana::_ob_end_clean';
while (ob_get_level() > self::$buffer_level)
{
@@ -731,7 +731,7 @@ final class Kohana {
}
// Store the Kohana output buffer
- ob_end_clean();
+ Kohana::_ob_end_clean();
}
}
@@ -2173,6 +2173,31 @@ final class Kohana {
return $written;
}
+
+ /**
+ * Ends the current output buffer with callback in mind
+ * PHP doesn't pass the output to the callback defined in ob_start() since 5.4
+ *
+ * @param callback $callback
+ * @return boolean
+ */
+ protected static function _ob_end_clean($callback = NULL)
+ {
+ // Pre-5.4 ob_end_clean() will pass the buffer to the callback anyways
+ if (version_compare(PHP_VERSION, '5.4', '<'))
+ return ob_end_clean();
+
+ $output = ob_get_contents();
+
+ if ($callback === NULL)
+ {
+ $handlers = ob_list_handlers();
+ $callback = isset($handlers[ob_get_level() - 1]) ? $handlers[ob_get_level() - 1] : NULL;
+ }
+
+ return is_callable($callback)
+ ? ob_end_clean() AND call_user_func($callback, $output)
+ : ob_end_clean();
+ }
} // End Kohana
@@ -2309,4 +2334,4 @@ class Kohana_404_Exception extends Kohana_Exception {
header('HTTP/1.1 404 File Not Found');
}
-} // End Kohana 404 Exception
\ No newline at end of file
+} // End Kohana 404 Exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment