Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7 global $user variable

Tags:

drupal

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?

like image 680
SN_26 Avatar asked Jul 04 '26 13:07

SN_26


1 Answers

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 $GLOBAL superglobal. 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.

like image 132
marcvangend Avatar answered Jul 08 '26 18:07

marcvangend



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!