ZF-11281: PHP notice when calling isSuccess() on a Zend_Service_Twitter response


I'm unsure whether this is a bug in the Twitter service, Zend_Rest_Client_Result, or the result of non-standard behaviour in the Twitter API itself.

Consider this code:

$api = new Zend_Service_Twitter([...]);

$params = array(
    'since_id' => '12345' // <-- id of latest tweet
$response = $api->status->userTimeline($params);
if ($response->isSuccess()) {

if this query returns tweets, everything works fine. If there are no tweets in the result (e.g. nothing has been posted since the tweet specified), the following PHP notice is generated by the isSuccess() call:

{quote} Notice: Undefined offset: 0 in /path/to/zf/Zend/Rest/Client/Result.php on line 184 {quote}

The cause seems to be the getStatus() call in Zend_Rest_Client_Result, which is running an xpath query looking for a field called 'status' in the XML response.

If the response does contain tweets the XML looks a little like this:

<?xml version="1.0" encoding="UTF-8"?>

If no tweets are returned, the XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>

It seems like Zend_Rest_Client_Result is expecting there to be a string field called status in the XML response, and for the Twitter service this works by fluke most of the time simply because the responses usually include tweets, which are in a block called . When there are no tweets in the result the notice is generated.


Simple fix. I've attached a patch which checks to see if $status[0] exists and returns false if it doesn't.

Reproducing test suite is included in patch.

Running ZF test suite showed no ill-effects from this patch.

Fix in trunk r23884 (PHP files) and r23890 (added forgotten XML file)

Hello, Adam. I will push [solve] button as proxy for You. If You want to release at next mini, You can merge these commits from trunk to 1.11 branch.


Not merged yet, merging shortly.

Fixed in release branch 1.11 at r23966