1

I'm using amazon product advertising api.

So I'm getting notices like "Trying to get property of non-object". Can anyone tell me how to fix this?

Here is my code

if(!is_null($result->Items[0]->ItemAttributes->ListPrice->FormattedPrice) && $result->Items[0]->ItemAttributes->ListPrice->FormattedPrice != '0'){
                $output_str .= '<span class="amazon-ad-listprice"><strong>List Price: </strong>'. $result->Items[0]->ItemAttributes->ListPrice->FormattedPrice .'</span>';
                }

Here is the var_dump of that part

'ListPrice' => object AmazonProduct_Price (1)
protected _values -> array (3)
'Amount' => string (4) "3999"
'CurrencyCode' => string (3) "USD"
'FormattedPrice' => string (6) "$39.99"

I'm getting that notices only in products that doesn't have those values..

I've tried using isset(). But its not working.

tereško
  • 58,060
  • 25
  • 98
  • 150
Giri
  • 4,849
  • 11
  • 39
  • 48
  • 1
    The problem could be anywhere in the chain of `$result->Items[0]->ItemAttributes->ListPrice->FormattedPrice`; you have to inspect each chain to make sure it's still an object. – Ja͢ck Nov 27 '12 at 02:55
  • Hi yes it is an object. And its working in all other products except the products which does not has that "ListPrice" object. So i'm looking for a function which checks whether objects exists or not. – Giri Nov 27 '12 at 03:09

1 Answers1

0

If it all depends on the existence of ListPrice you could just write a simple condition:

if (isset($result->Items[0]->ItemAttributes->ListPrice)) {
    // do stuff with ListPrice->FormattedPrice;
}
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309