0

First of I think I have tried all the solutions I have come across and still have an issue none the less..

facebookResponse Object
(
    [__construct:facebookResponse:private] => 
    [__resp] => stdClass Object
        (
            [data] => stdClass Object
                (
                    [id] => 00000000000
                    [name] => Random.User
                    [first_name] => Random
                    [last_name] => User
                    [link] => http://www.facebook.com/Random.User
                    [username] => Random.User
                    [birthday] => 11/10/1980
                    [gender] => male
                    [email] => [email protected]
                    [timezone] => -7
                    [locale] => en_US
                    [verified] => 1
                    [updated_time] => 2011-08-22T02:56:33+0000
                )

            [code] => 200
            [time] => 0.600512
            [length] => 386
            [type] => text/javascript; charset=UTF-8
        )

)

above is an example of the output object. I am looking for specifics, some of which sometimes don't exist. Where if they don't exist I just want to catch the fact flag it as "none" for my DB and move on to the next. For me Im not so lucky. no matter how I approach it I am running into errors..

whether i do isset() !isset() empty() !empty() or some combination of the above trying to catch it, as empty, null, undefined, blank, or just not even present.

Example you will see that there is no location->name object in the above sample output. So my latest attemt(s) to catch it as not there is

if((isset($fb_result->location->name))
    AND(!empty($fb_result->location->name))
   AND(trim($fb_result->location->name) !== ""))
   {
        $currenthome = $fb_result->location->name;
    }
   else
   {
    $currenthome = "none";
    }

my error with the above is "Undefined property: stdClass::$location" and no matter how I try to catch it, i still get the same thing.

2 Answers 2

1

You need to check for "location" attribute first, then go deeper

if(!empty($fb_result->location) && !empty($fb_result->location->name))
    $currenthome = $fb_result->location->name;
else
    $currenthome = 'none';
Sign up to request clarification or add additional context in comments.

Comments

1

You might want to look at the Reflection API.

2 Comments

good suggestion, don't know if its specificly what I need for what I am doing currently, however. Does look like something I can use in the future for some other things I have in my pipeline. thanks..
can't we use the property_exists for this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.