print_r($p->attachments)
produces:
Array
(
[0] => stdClass Object
(
[id] => ...
[url] => http://
You can use isset() for check the array:
if(isset($p->attachments[0])){
echo $p->attachments[0]->url;
}
else {
//some error?
}
Or if you know that you are only going to be checking index 0 then you can do this way
$array = $array + array(null);
So if the original $array[0] was unset, now it is null
dunno why it returns you a value and informs you that there is undefined offset 0. strange.
can you check this (since attachments is an array you should do this that way):
if ( count($p->attachments) > 0 ){
foreach ($p->attachments AS $att){
//do the stuff if attachement
}
}