RFC on ob_get/ob_end_clean, was Re: [PHP-CVS] cvs: php4 /ext/session session.c ...

From: Date: Fri, 01 Mar 2002 08:33:54 +0000
Subject: RFC on ob_get/ob_end_clean, was Re: [PHP-CVS] cvs: php4 /ext/session session.c ...
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9529@lists.php.net to get a copy of this message
Yasuo Ohgaki wrote:
Added ob_get_status() to get array of buffers and it's status. (DO NOT document this function yet) Fixed crash bug with ob_end_*() function. ob_end_*() will not delete buffers that may not be deleted. php_start_ob_buffer() and php_ob_set_internal_handler() takes parameter for if the buffer created may be deleted or not. Added 3rd parameter "bool erase" to ob_start(). If FALSE, buffer may not be deleted until script finshes. Changed ob_*() function that have void return type to bool. All ob_*() functions return TRUE for success, FALSE for failure.
from looking at the codebase here in our company i find that we have just two use cases for the ob_...() stuff: - calling ob_start("callback") only and have callback() do the all the work on script termination - or the following sequence:
    ob_start();
    /* some output */;
    $var = ob_get_contents();
    ob_clean();
especially
    ob_start(); print_r($var); error_log(ob_get_contents()); ob_end_clean();
so i've been thinking about a combination of of ob_get_contents() and ob_end_clean() for a long time i have come up with several different naming/implementation variants - a new function - string ob_get_clean(void) or - string ob_end_get(void) - an optional boolean parameter to an existing function - string ob_get_contents(bool $clean = false) or - string ob_end_clean(bool $return_contents = false) - an optional int parameter to an existing functions and some predefined constants - string ob_get_contents(int $option = 0)
    with OB_NONE -> no operation (0)
         OB_CLEAN -> clean output buffer
         OB_FLUSH -> flush output buffer
         OB_END -> end output buffering (current level)
         OB_APPLY_CALLBACK -> apply callback registered with
            ob_start, if any, on returned buffer contents
-- Hartmut Holzgraefe hartmut@six.de http://www.six.de +49-711-99091-77 Wir stellen für Sie aus auf der CeBIT 2002 und freuen uns in Halle 6 auf Ihren Besuch am Stand H 18

« previous php.cvs (#9529) next »