Most probably the code you are using is trying to access logged in user’s data before init action. Since the current user is set on ‘set_current_user’ hook’ which is just before init, any function trying to access current user data should be called on or after init action.

If you need to check something like user roles right after you load your plugin but before continuing, you can do something like this:
`
function something_check_access () {
$current_user = wp_get_current_user();
$roles = $current_user->roles;
$role = array_shift($roles);