views:

354

answers:

2

Hey guys

I have this piece of code which works 90% of the time:

$user_details=$fb->api_client->users_getInfo($fb_user, array('last_name','first_name','proxied_email'));
$firstName=$user_details[0]['first_name'];

But sometimes I get this error:

Fatal error: Cannot use string offset as an array for line
$firstName=$user_details[0]['first_name'];

I have read several people report the same issue - but I'm still not clear as to what is the reason - Am I getting this error because facebook is not returning any results or am I getting because it is returning only a single array instead of array of arrays.

This is the fix I'm thinking of:

if (!is_array($user_details)) {
$firstName='';
}
else
{
$firstName = ($user_details[0]) ? $user_details[0]['first_name'] : $user_details['first_name'];
}

Also if I'm not getting the name - is it because of a timeout issue or something else?

Thanks

A: 

just modif yout php.ini. set parameter or add : magic_quotes_gpc=off

rey1024
i dont see how that could fix the issue as magic_quotes_gpc is already off.
Jayrox
A: 
$user_details=$fb->api_client->users_getInfo($fb_user, array('last_name','first_name','proxied_email'));
            if (!is_array($user_details)) {
                $firstName='';
                $lastName='';
            }
            else
            {
                $firstName = ($user_details[0]) ? $user_details[0]['first_name'] : $user_details['first_name'];
                $lastName = ($user_details[0]) ? $user_details[0]['last_name'] : $user_details['last_name'];
            }
Gublooo

related questions