note 93633 added to function.ob-start

From: Date: Sun, 20 Sep 2009 00:31:33 +0000
Subject: note 93633 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-160861@lists.php.net to get a copy of this message
With ob callback: note that the second parameter sent to your method won't help you differentiate between flush calls and calls to ob_clean, but the buffer contents is sent in both cases, so you end up parsing data that isn't going to be used. Also, note that the constant PHP_OUTPUT_HANDLER_START is never actually sent, rather the integer "3" turns up on first flush: <?php function ob_handler($string, $flag){ static $input = array(); $done = false; switch($flag){ case PHP_OUTPUT_HANDLER_START: $flag_sent = "PHP_OUTPUT_HANDLER_START ($flag)"; break; case PHP_OUTPUT_HANDLER_CONT: $flag_sent = "PHP_OUTPUT_HANDLER_CONT ($flag)"; break; case PHP_OUTPUT_HANDLER_END: $done = true; $flag_sent = "PHP_OUTPUT_HANDLER_END ($flag)"; break; default: $flag_sent = "Flag is not a constant ($flag)"; } $input[] = "$flag_sent: $string<br />"; $output = "$string<br />"; if(!$done) return $output; // print_r($input, 1) causes an error and var_export just doesn't work $output .= '<br />'; foreach($input as $k=>$v) $output .= "$k: $v"; return $output; } ob_start('ob_handler'); echo 'flush'; ob_flush(); echo 'flush 2'; ob_flush(); echo 'clean'; ob_clean(); echo 'flush 3'; ob_flush(); echo 'end flush'; ob_end_flush(); ?>   flush flush 2 flush 3 end flush 0: Flag is not a constant (3): flush 1: PHP_OUTPUT_HANDLER_CONT (2): flush 2 2: PHP_OUTPUT_HANDLER_CONT (2): clean 3: PHP_OUTPUT_HANDLER_CONT (2): flush 3 4: PHP_OUTPUT_HANDLER_END (4): end flush I suppose the START flag problem *may* be a bug but I'm not able to upgrade before reporting since I must have the same version as my server (I'm on PHP 5.2.6). If anyone has 5.2.11 or other stable version feel free to test/report as you see fit. ---- Server IP: 80.64.47.13 Probable Submitter: 89.130.23.72 ---- Manual Page -- http://www.php.net/manual/en/function.ob-start.php Edit -- https://master.php.net/note/edit/93633 Del: integrated -- https://master.php.net/note/delete/93633/integrated Del: useless -- https://master.php.net/note/delete/93633/useless Del: bad code -- https://master.php.net/note/delete/93633/bad+code Del: spam -- https://master.php.net/note/delete/93633/spam Del: non-english -- https://master.php.net/note/delete/93633/non-english Del: in docs -- https://master.php.net/note/delete/93633/in+docs Del: other reasons-- https://master.php.net/note/delete/93633 Reject -- https://master.php.net/note/reject/93633 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160861) next »