Get user object within module I need the $user object within a module am creating. But am not able to get it. I have created a module that extends user object hold more data. Its working fine. I am also 
able to use this values in theme files. But am not able to get it in any function within
a module.

The standard value $user-&gt;name; or my custom value $user-&gt;data['privacy']; nothing is available in module.

I tried using this

global $user;
$user = $user-&gt;name;


What is the mistake here? Is it that global is not the right way to get the user object?
You're currently referencing the global $user object, then in the very next line you're overwriting it with a string (the username). So your global $user object is destroyed, and you will probably be logged out of the site (as well as the code not working as expected).

You're referencing the global user object in the correct way, but by default it isn't fully loaded (i.e. with fields attached, etc). To get the extra data you should use the user_load() function like so:

global $user;

// Get the fully loaded user object
$account = user_load($user-&gt;uid);

// Get the username. Make sure you don't override the global $user object here!
$username = $account-&gt;user.

// Get a field value.
$field_items = field_get_items('user', $account, 'field_foo');