如何正确访问数组对象

I've a result from a webservice's query and I would like to get some values from it. It works but I have PHP notice issues, so I'm probably doing something wrong.

This is the $items variable content :

stdClass Object
(
    [response] => stdClass Object
        (
            [0] => stdClass Object
                (
                    [id] => 275
                    [corpid] => 16107
                    [name] => default
                    [description] => 
                    [status] => ok
                    [nbSteps] => 7
                )

            [defaultItem] => 275
        )

    [error] => 
    [status] => success
)

So I tried something like :

foreach ( $items->response AS $key => $item ) {
    if ( $item->name == 'default' ){ // Line 106
        $Id = $item->id;
    }
}

It works, $Id is equal to 275 but PHP returns a notice :

Notice: Trying to get property of non-object in /home/web/dev/webservice-form.php on line 106

Any help would be greatly appreciated.

EDIT : This is the content of the $item variable (taken from the foreach loop) :

stdClass Object
(
    [id] => 275
    [corpid] => 16107
    [name] => default
    [description] => 
    [status] => ok
    [nbSteps] => 7
)

275

Please note that the '275' is a part of the result.

The problem is the defaultItem entry in your inner object. Your loop will at some point reach this and try to access name, which doesn't exist, because there is no object.

Should be easily solveable with is_object().

You have mixed types, one being an objects, and one an int value, try checking what each item is:

foreach ( $items->response AS $key => $item ) {

    if(is_object($item) && $item->name == 'default'){ // Line 106
        $Id = $item->id;
    }
    else {
         $Id = $item; // assume it's scalar value
    }
}

Obviously it would depend on what else you can expect on what other check you need to add in there..