note 92467 deleted from function.include-once by danbrown
| From: | danbrown@php.net | Date: | Sun, 26 Jul 2009 15:59:36 +0000 |
| Subject: | note 92467 deleted from function.include-once by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-158748@lists.php.net to get a copy of this message | ||
Note Submitter: mccarre at uwindsor dot ca
----
I do a lot of my web development using AJAX, and therefor at the top of a lot of my php pages I have
an if statement to check to see if a post variable for a function call exists, then call that
function if it exists. Ie:
<?php
if($_fnc = $_POST['fnc']) {
$GLOBALS['suppressOutput'] = true;
unset($_POST['fnc']);
$return = call_user_func($_fnc, $_POST);
if(is_string($return))
print $return;
else
print json_encode($return);
}
?>
The problem with this and include once, is if one of your first include files has this code at the
top it will try to run the function before evaluating all the functions in the other include files.
So you will get functions not being found.
This isn't the most elegant solution, however you can use a globals variable as a flag. If the
files flag is the only one set and none others are set then include the file.
A more elegant solution would be a function called "include_last".