Pearのデストラクタの仕組みがわかったのですが、そのデストラクタの中でもうひとつ 仕事がされているようです。
PEARのデストラクタでは、次のように書かれています。
//_PEAR_call_destructors関数の中 // Now call the shutdown functions if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) { foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) { call_user_func_array($value[0], $value[1]); } }
call_user_func_array関数で$GLOBALS['_PEAR_shutdown_funcs']に登録された関数をコールして いるようです。なんらか終了時に実行したい関数がある場合、$GLOBALS['_PEAR_shutdown_funcs']に 登録すれば実行されそうです。
そのためPEARクラスには、$GLOBALS['_PEAR_shutdown_funcs']に関数を登録するための関数が 用意されています。
//終了時に呼ばれる関数を登録 function registerShutdownFunc($func, $args = array()) { $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); }
registerShutdownFuncには、call_user_func_arrayと同様にコールバック関数と引数の配列を 渡します。
Copyright 1997-2010 BBB All rights reserved.