Why would $user->sid be undefined?
If you are not logged in the property will be undefined. This is all I've got for the anonymous user

object(stdClass)#7 (4) {
  ["uid"]=&gt;
  int(0)
  ["hostname"]=&gt;
  string(9) "XXX.XXX.XXX.XXX"
  ["roles"]=&gt;
  array(1) {
    [1]=&gt;
    string(14) "anonymous user"
  }
  ["cache"]=&gt;
  int(0)
}