JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix db_get_value after mysql->mysqli upgrade
[wfpl.git] / file_run.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
9 # This function makes it easier to put everything in functions like you should.
10 #
11 # Instead of putting everything in the global namespace and having it run when
12 # you include the file, put everything in functions. This function makes it so
13 # you can both include (require_once) the file, and call its main function in
14 # one easy step.
15
16 # EXAMPLE
17 #
18 # list($user, $pass) = file_run('db_password.php');
19 #
20 # the file db_password.php would be like so:
21 #
22 #     function db_password_main() {
23 #           return array('me', 'secret');
24 #     }
25
26 function file_run($filename /* args... */) {
27         $args = array_slice(func_get_args(), 1);
28         require_once($filename);
29         $func = basename($filename, '.php') . '_main';
30
31         if(function_exists($func)) {
32                 return call_user_func_array($func, $args);
33         }
34 }