There is a page in my website that generates this notice:

Notice: Trying to get property of non-object in fb_get_object_fbu() (line 902 of modules/fb/fb.module).

Here is the code from fb.module at line 902:
902: elseif ($object->uid > 0) {
903: // This can be expensive on pages with many comments or nodes!
904: $fbu = fb_get_fbu($object->uid);
905: }

It shows up both on facebook connect pages and canvas pages for all users.

The same notice appears twice after each visit to that page.

The notice does not appear on that page but at any page right after navigating from that page, i.e., if I go to page B after visiting page A the notice shows up on page B but I do not see it in page B if I go to B after C, D,...

It is not clear to me what is the source of the error. Here is the code from Facebook page.

Comments

Dave Cohen’s picture

Can you add this code after the elseif clause (i.e. at line 906), just to see better what's happening?

if (!is_object($object)) {
  print ("<pre> It is not an object!\\n\n");
  print_r($object);
  print ("</pre>");
  flush();
}

Then paste here what appears at the top of the page.

nvd_ai61’s picture

Thanks for the help Dave. It helped me figure out that somewhere in my code I have:

$user=user_load($member['uid']);
print theme('username',array('account'=>$user)).'
';

now, if the user is that being loaded was deleted before (which sets $user to FALSE), calling the theme function causes that error in fb.module at line 902. I can see that fb_get_obj_fbu has to do with the users. Is fb_get_obj_fbu like a preprocess hook to theme username so it gets called when theme is called? maybe a boundary check of the $object is required to make sure that the mistakes in other modules do not cause error in fb.module. I changed my code to: $user=user_load($member['uid']);
if($user!=FALSE){
print theme('username',array('account'=>$user)).'
';
}

and the error went away.
Thanks again.

dubs’s picture

I also have this error when comments are there for users not on the system. A workaround for me is to change this line 474 in fb_connect.module: -

- if ($fbu = fb_get_object_fbu($account)) {
+ if (isset($variables['link_path']) && $fbu = fb_get_object_fbu($account)) {

This is how the original theming function checks if a user is live or not.

Dave Cohen’s picture

Status: Active » Fixed

I've added a check that $account is not FALSE.

dubs’s picture

Great - thanks for the module and such a quick fix.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dubs’s picture

Status: Closed (fixed) » Active

Sorry, but the issue is still there actually :-(

It is coming from the comment user's profile. For now I've done an is_object check at the top of the function, but that probably isn't ideal. Here's what comes through as the $object variable when it fails: -

caSper Pepperlane

Dave Cohen’s picture

Try to paste that again with <code> tag. Upload patch if possible.

dubs’s picture

Oh yeah, whoops. Here you are: -

<span class="username">caSper Pepperlane</span>

thanks...

Dave Cohen’s picture

Can you make that code dump a whole stack? Like so:

if (!is_object($object)) {
  print ("<pre> It is not an object!\\n\n");
  print_r(debug_backtrace());
  print ("</pre>");
  flush();
}

The function expects an object and I don't get why it would be passed anything else.