When using the register_shutdown_function command in php 4. The registered functions are called in the order that you register them.



This is important to note if you are doing database work using classes that register shutdown functions for themselves.



You must register the shutdown_functions in the order that you want things to shutdown. ( ie the database needs to shutdown last )



Example of what will not work but what you might expect to work :



<?php

class database {



function database () {

echo "connect to sql server -- (database :: constructor)<br>

" ;

register_shutdown_function ( array( & $this , "phpshutdown" ) );

$this -> connected = 1 ;

}



function do_sql ( $sql ) {

if ( $this -> connected == 1 ) {

echo "performing sql -- (database :: do_sql)<br>

" ;

} else {

echo " ERROR -- CAN NOT PERFORM SQL -- NOT CONNECTED TO SERVER -- (database :: do_sql)<br>

" ;

}

}



function phpshutdown () {

echo "close connection to sql server -- <b>(database :: shutdown)</b><br>

" ;

$this -> connected = 0 ;

}

}



class table {



function table ( & $database , $name ) {

$this -> database =& $database ;

$this -> name = $name ;

echo "read table data using database class -- name= $this -> name -- (table :: constructor)<br>

" ;

register_shutdown_function ( array( & $this , "phpshutdown" ) );

$this -> database -> do_sql ( "read table data" );

}



function phpshutdown () {

echo "save changes to database -- name= $this -> name -- <b>(table :: shutdown)</b><br>

" ;

$this -> database -> do_sql ( "save table data" );

}

}



$db =& new database ();



$shoppingcard =& new table ( & $db , "cart " );

?>



Output of the above example is :-



connect to sql server -- (database :: constructor)

read table data using database class -- name=cart -- (table :: constructor)

performing sql -- (database :: do_sql)

close connection to sql server -- (database :: shutdown)

save changes to database -- name=cart -- (table :: shutdown)

ERROR -- CAN NOT PERFORM SQL -- NOT CONNECTED TO SERVER -- (database :: do_sql)