note 92467 added to function.include-once
| From: | mccarre at uwindsor dot ca | Date: | Sun, 26 Jul 2009 01:15:47 +0000 |
| Subject: | note 92467 added to function.include-once | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158726@lists.php.net to get a copy of this message | ||
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".
----
Server IP: 66.207.199.35
Probable Submitter: 24.57.89.111
----
Manual Page -- http://www.php.net/manual/en/function.include-once.php
Edit -- https://master.php.net/note/edit/92467
Del: integrated -- https://master.php.net/note/delete/92467/integrated
Del: useless -- https://master.php.net/note/delete/92467/useless
Del: bad code -- https://master.php.net/note/delete/92467/bad+code
Del: spam -- https://master.php.net/note/delete/92467/spam
Del: non-english -- https://master.php.net/note/delete/92467/non-english
Del: in docs -- https://master.php.net/note/delete/92467/in+docs
Del: other reasons-- https://master.php.net/note/delete/92467
Reject -- https://master.php.net/note/reject/92467
Search -- https://master.php.net/manage/user-notes.php