Global variable issue

Discussion in 'PHP' started by archard, Jul 6, 2008.

  1. #1
    I'm making a module for Drupal, and in many of my functions I use the global $user object, which contains information about the currently logged in user. However, in one of my functions the $user object always seems to display information for the admin user (user ID 1). It never contains information about the user that's currently viewing the page, like it should. What are some things that would cause a global variable to misbehave like this? I can't for the life of me figure out why this is happening.
     
    archard, Jul 6, 2008 IP
  2. zerofill

    zerofill Member

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #2
    What happens if you specifically pass the value of $user to the function?

    Like:
    function user_info($user) {
    }

    user_info($user);

    Does it still do the same thing?
     
    zerofill, Jul 6, 2008 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    yes, you can send variables using properties to functions. But by declaring $GLOBALS['user'] you can use it everywhere without adding it to function properties.
     
    EricBruggema, Jul 12, 2008 IP