Would appreciate it, if anyone can let me know how we can set the global $user variable, so that we don’t have to keep re-declaring it in each function, to access its contents. How can we declare it so that all the functions in a module can use it?
Would appreciate it, if anyone can let me know how we can set the
Share
The type of global you’re looking for (available always, in every scope) is called a superglobal in PHP. You cannot declare new superglobals, but you can access all globals directly because they are part of the
$GLOBALsuperglobal. In other words, you can use$GLOBALS['user']to access the $user global directly.See also create superglobal variables in php? for more info and alternative methods.