Re: Multiple callback_outputs for ob_start

From: Date: Thu, 08 Dec 2005 12:44:25 +0000
Subject: Re: Multiple callback_outputs for ob_start
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-227132@lists.php.net to get a copy of this message
Chris Shiflett wrote:
Mathijs wrote:
How can i add more callback_outputs to ob_start? I want to have both: ob_start('switchContent'); and: ob_start('ob_gzhandler');
I don't think you can, but you could have a single function that calls both, then specify that function in ob_start().
I think you can by simply stacking multiple output buffers on top of each other: ob_start('switchContent'); // first buffer, for first callback ob_start('ob_gzhandler'); // second buffer, for second callback take care to define the handlers in the 'right' order (the order that they are run in may be important to your output/code) // rest of code. I implemented a class once that stacks a list of callbacks which could then all be run by its callback handler, psuedo-code: class CB { private static $cbs = array(); public static function addCB($cb) { if (is_callable($cb)) { self::$cbs[] = $cb; } } public static function run($data) { foreach (self::$cbs as $cb) { $data = call_user_func($cb, $data); } return $data; } } ob_start( array('CB','run') );
Chris


« previous php.general (#227132) next »