ZF-9547: Handle 'empty' Amazon book search results

Issue Type: Bug Created: 2010-03-26T13:00:29.000+0000 Last Updated: 2010-04-16T08:13:10.000+0000 Status: Resolved Fix version(s): - 1.10.4 (28/Apr/10)

Reporter: Tim Fountain (tfountain) Assignee: Michelangelo van Dam (dragonbe) Tags: - Zend_Service_Amazon

Related issues: Attachments: - amazon-response-invalid.xml


I'm using Zend_Service_Amazon to display book information, using itemSearch() to search by ISBN. Every now and then, Amazon seems to return a valid result without any data for these queries, which causes the following fatal PHP error from ZF:

Catchable fatal error: Argument 1 passed to Zend_Service_Amazon_Item::__construct() must be an instance of DOMElement, null given, called in /home/tim/zend-framework/ZendFramework-1.10.1/library/Zend/Service/Amazon/ResultSet.php on line 111 and defined in /home/tim/zend-framework/ZendFramework-1.10.1/library/Zend/Service/Amazon/Item.php on line 118

Here's an example script, you'll need to add valid API key data:

<pre class="highlight">
$isbn = '0750640162'; // doesn't work
//$isbn = '0754512673'; // does work

$client = new Zend_Service_Amazon('AMAZON_API_KEY', 'UK', 'AMAZON_SECRET_KEY');

$results = $client->itemSearch(array(
    'SearchIndex' => 'Books',
    'Power' => 'isbn:'.$isbn,
    'ResponseGroup' => 'Large,ItemAttributes,Images,EditorialReview'

$totalResults = $results->totalResults();
if ($totalResults == 1) {
    var_dump($results->current()); // causes PHP fatal

There are two ISBN numbers at the top of this script. The first causes the error, the second works fine. Both of these ISBNs are perfectly valid books that are listed on

Unfortunately the problem is intermittent. I'm getting the error consistently at the moment, but the same search was working fine last week. I have had this problem in the past with other ISBNs though, so this isn't an isolated case specific to this book.

It does seem like this is partly a problem on Amazon's side, but it would be nice if ZF could detect the invalid result and handle it gracefully, as I have no way of catching the PHP fatal.


Posted by Tim Fountain (tfountain) on 2010-03-26T13:06:06.000+0000

Attached are the raw XML responses I'm currently getting from Amazon for the two ISBNs in my example script. You'll see in the failing one that the XML indicates that there was 1 result matching the search, but no s are included.

Posted by Michelangelo van Dam (dragonbe) on 2010-04-16T08:13:10.000+0000

Fixed the issue and merged it with 1.10 branch (r21883)

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.