Static variable scope in drupal I have a hook_user_load function where I am loading some extra user info into the $users array.  I am having trouble storing the info in a static array and would appreciate it if someone could let me know what is wrong in the following function:

function mymodule_user_load ($users) {

    static $my_users = array();

    foreach ($users as $uid =&gt; $account) {
        // Only handle authenticated users.
        if ($uid &gt; 0) {

            // Have we loaded this user before?
            if (isset($my_users[$uid])) {
                $users[$uid]-&gt;info = $my_users[$uid];
            }
            else {
                //Call another function to load user info
                $my_users[$uid] = load_user_info($uid);
                $users[$uid]-&gt;info = $my_users[$uid];
            }
        }
    }
}


Basically, the variable $my_users on the first time I load the user profile page, will be an empty array and I have to call the load_user_info() function to fill the array with the info.  If I refresh the user profile page again, this function will run a second time, and the following if (isset($my_users[$uid])) code should evaluate to true and so it won't have to go to the else statement and run the load_user_info() function again.  However, it is not working.  Basically, each time hook_user_load runs, the $my_users variable is empty, meaning it is getting initialized each time.  Isn't a static variable supposed to be only initialized once?

Would appreciate any help on this.  Thanks.
Static variables are initialised once per page build. As soon as you refresh the page you'll lose any vars declared in your page build, including static ones.

If you want to persist data between page loads you need to use session storage