Imcompatibility shutdown and ob_filter

Date 2007-03-24 05:50:55 | Category: PHP

in englishin japanese
There are important difference in order of functions for shutdown and output-buffering between PHP4.x/5.0.x and PHP5.1

<?php
register_shutdown_function( 'sf' ) ;
ob_start( 'ob' ) ;
echo 'main ' ;

function ob( $s )
{
	return $s.'ob ' ;
}

function sf()
{
	echo 'sf ' ;
}
?>

The results excecuting this code...
PHP4.4.4 and PHP5.0.3
main ob sf 


PHP5.1.3
main sf ob 


You can understand they are far different each other.
Thus, we have to code like this style for cushoning the versions of PHP.
<?php
register_shutdown_function( 'sf' ) ;
ob_start( 'ob' ) ;
echo 'main ' ;

function ob( $s )
{
	return $s.'ob ' ;
}

function sf()
{
	while( @ob_end_flush() ) ; // here
	echo 'sf ' ;
}
?>

With this code, Both PHP4.x/5.0.x and PHP5.1.x run same order. (main, ob, sf)

If you want the order of (main, sf, ob), you have to call the shutdown function from the output-buffering function.




You can read more news at PEAK XOOPS.
http://xoops.peak.ne.jp

The URL for this story is:
http://xoops.peak.ne.jp/md/news/index.php?page=article&storyid=414