Imcompatibility shutdown and ob_filter
Date 2007-03-24 05:50:55 | Category: PHP
|
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
PHP5.1.3
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.
|
|