Re: how-to-include
| From: | Gonzalo Vera | Date: | Thu, 17 Aug 2000 14:35:23 +0000 |
| Subject: | Re: how-to-include | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-1914@lists.php.net to get a copy of this message | ||
Jess:
From the user manual (Ch. 11: Control Structures - include):
--------------------------------
Please note that both include() and require() actually pull the
contents of the target file into the calling script file itself; they
do not call the target via HTTP or anything like that. So any variable
set in the scope in which the inclusion happens will be available
within the included file automatically, since it has effectively
become a part of the calling file.
include( "file.inc?varone=1&vartwo=2" ); /* Won't work. */
$varone = 1;
$vartwo = 2;
include( "file.inc" ); /* $varone and $vartwo will be available in file.inc */
--------------------------------
You cannot pass values URL-like to an INCLUDed function. You must
first assign the variables.
> I am wondering if anyone has an idea on how I would get this to work
> or if anyone has any ideas on a more efficient way to do this. I
> want this kind of affect.
> <?
> include("ext_functions.php?function=function_name");
> ?>
So to pass variables to the include you just place them before the
include, as the manual says. Thing is, to pass values to a function
you must specify these in the functions' parameters, like:
$var_one="hello";
$var_two="world!";
include("myfunctions.php"); //this having, say, function1
$myfunction=function1($var_one,$var_two);
As far as I get it, the call to a function doesn't take with it the
values of variables (don't know if theres a way to modify the scope of
variables) but anyway, if you are INCLUDEing functions you would be
better off pasing values through parameters. Probably cleaner coding.
> and ext_functions.php would have a bunch of functions in it with a part at
> the top that would be something like this
> $myfunction = $function;
> $function();
I'm not sure this works, haven't tried it, probably does (if it works,
I'd be interested in knowing so). Wouldn't it be better to use SWITCH
to select which function you want to call?
Gonzalo.