Proper use of Variable Scope in PHP

I’ve got a handful of variables that I need access to in more functions than I initially thought.

What would be the best way of including them in my growing list of functions?

I’ve got something like

$site = 'a';
$admin = 'b';
$dir = 'c';
$ma_plug = 'd';
$base = 'e';
//Etc.

I need almost all of those in a large handful of my functions. I was initially doing

function a(){
    global  $site, $admin, $dir, $ma_plug, $base;
    //Write the A function
}
function b(){
    global  $site, $admin, $dir, $ma_plug, $base;
    //Write the B function
}

That was great, until I realized I’ve got more functions to write than I initially thought.

What would be the best way to get all those variables into the scope of (almost) each function? Like I’ve done? Or something like using Constants? I’d like to avoid using session() if at all possible

Leave a Reply

*

Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories