Issues

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

Issue Type: Bug Created: 2011-04-12T10:13:23.000+0000 Last Updated: 2011-05-03T14:30:47.000+0000 Status: Resolved Fix version(s): - 1.11.6 (05/May/11)

Reporter: Tim Fountain (tfountain) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Rest_Client

  • Zend_Service_Twitter

Related issues: Attachments: - ZF-11281.patch

Description

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:

<pre class="highlight">
$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:

<pre class="highlight">
<?xml version="1.0" encoding="UTF-8"?>
..12345
        [...]
    ..12344
        [...]
    
    [etc.]

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

<pre class="highlight">
<?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.

Comments

Posted by Adam Lundrigan (adamlundrigan) on 2011-04-29T02:59:37.000+0000

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.

Posted by Adam Lundrigan (adamlundrigan) on 2011-04-29T03:08:05.000+0000

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

Posted by Satoru Yoshida (satoruyoshida) on 2011-05-03T09:41:26.000+0000

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.

Thanks.

Posted by Ralph Schindler (ralph) on 2011-05-03T14:18:42.000+0000

Not merged yet, merging shortly.

Posted by Ralph Schindler (ralph) on 2011-05-03T14:30:47.000+0000

Fixed in release branch 1.11 at r23966

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts