+<?php
+
+# this file is much like register_shutdown_function(), except:
+#
+# 1. it uses the standard name you know and love
+#
+# 2. wfpl will call it before calling display_messages() for you, or before
+# calling session_save_messages() (when it's about to redirect.
+
+$GLOBALS['wfpl_atexit_queue'] = array();
+
+# your passed function will be called by run.php just before display_messages
+# (or right before an http redirect)
+#
+# order is fifo
+function atexit($func, $args) {
+ $GLOBALS['wfpl_atexit_queue'][] = array($func, $args);
+}
+
+# call the functions queued up by atexit()
+# atexit() can be called from one of these functions (even the last)
+function atexit_now() {
+ while(count($GLOBALS['wfpl_atexit_queue'])) {
+ list($func, $args) = array_shift($GLOBALS['wfpl_atexit_queue']);
+ call_user_func_array($func, $args);
+ }
+}
+
+# for those cases where display_messages() and session_save_messages() don't
+# get called automatically by wfpl:
+register_shutdown_function("atexit_now");