Is using a "global" user in Drupal dangerous?
2 answers
Global variables can be dangerous for many reasons, some of which include:
- Clutters namespaces
- This makes maintenance difficult and encourages monkeypatching, as globals can be changed from anywhere.
- They are not referential.
- In memory-managed languages, global variables can be a source of memory leaks.
- They make debugging especially difficult in large applications / sites, as it is difficult to track where they are installed and modified.
Nothing poses much of a threat to your use case. It should be good. If you are very scared, you can make sure that $ user-> uid is an integer before evaluating:
function myFunction($bla) {
global $user;
if( is_int($user->uid) ){
if (isAuthenticated($user->uid)) {
print $secretCode;
}
}
}
But this is probably not needed.
+4
c_harm
source
to share