JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix db_get_value after mysql->mysqli upgrade
[wfpl.git] / atexit.php
1 <?php
2
3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
7
8 # this file is much like register_shutdown_function(), except:
9 #
10 # 1.    it uses the standard name you know and love
11 #
12 # 2.    wfpl will call it before calling display_messages() for you, or before
13 #       calling session_save_messages() (when it's about to redirect.
14
15 $GLOBALS['wfpl_atexit_queue'] = array();
16
17 # your passed function will be called by run.php just before display_messages
18 # (or right before an http redirect)
19 #
20 # order is fifo
21 function atexit($func, $args) {
22         $GLOBALS['wfpl_atexit_queue'][] = array($func, $args);
23 }
24
25 # call the functions queued up by atexit()
26 # atexit() can be called from one of these functions (even the last)
27 function atexit_now() {
28         while(count($GLOBALS['wfpl_atexit_queue'])) {
29                 list($func, $args) = array_shift($GLOBALS['wfpl_atexit_queue']);
30                 call_user_func_array($func, $args);
31         }
32 }
33
34 # for those cases where display_messages() and session_save_messages() don't
35 # get called automatically by wfpl:
36 register_shutdown_function("atexit_now");