View Single Post
Old 06-23-2008, 04:02 AM   #6 (permalink)
delayedinsanity
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

I'm not sure what he's up to there, but you only need to declare your variables global if you set them in the global scope (ie, outside a function, or inside a function that declares them global) and you want to use them inside of another function. ie

PHP Code:
// included file, echo.tpl
--
echo 
$var;
--

//your script

$var "hello world!";
include (
'echo.tpl'); // automagically recognizes $var, because the include is treated as though it were part of the parent script

function doesntWork()
{
    echo 
$var;
}

function 
works ()
{
    global 
$var

    
echo $var;
}

doesntWork();
works(); 
If you placed those functions inside the include, they'd work (or not) the same as if they were directly part of the parent script.
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
Dave (06-24-2008)