I have a variable which contains data that would be accessed by different parts (fucntions) of my program. The problem is from what I read and tried with PHP, a function can only access variables that are within the function, or passed as an argument. This is making my function names very long as all the function are having these shared variables in their parameters.
$sharedVariable = 'hello';
function myfunc ()
{
echo ( "This is the shared variable: " . $sharedVariable );
}
myfunc();
When I do this, I don't see the word 'hello' coming up. Instead I have to end up doing this :
$sharedVariable = 'hello';
function myfunc ($sharedVar)
{
echo ( "This is the shared variable: " . $sharedVar );
}
myfunc($sharedVariable );
Is there any (safe, and secure) way to get the first one to work with out have all my functions having the same arugment being passed?