jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
777 stars 235 forks source link

Codebird throwing warnings: "Creating default object from empty value" #212

Closed GreenFootballs closed 6 years ago

GreenFootballs commented 6 years ago

My PHP error log is suddenly filling up with tons of warnings thrown by Codebird:

PHP Warning: Creating default object from empty value in /PATH/codebird.php on line 2294

This just started a couple of days ago, after working fine for a long, long time. The lines in question are in the function "_appendHttpStatusAndRate" and it seems to be throwing the warning about the httpstatus property:

protected function _appendHttpStatusAndRate($reply, $httpstatus, $rate)
  {
    switch ($this->_return_format) {
      case CODEBIRD_RETURNFORMAT_ARRAY:
        $reply['httpstatus'] = $httpstatus;
        $reply['rate']       = $rate;
        break;
      case CODEBIRD_RETURNFORMAT_OBJECT:
        $reply->httpstatus = $httpstatus;
        $reply->rate       = $rate;
        break;
      case CODEBIRD_RETURNFORMAT_JSON:
        $reply             = $this->_json_decode($reply);
        $reply->httpstatus = $httpstatus;
        $reply->rate       = $rate;
        $reply             = json_encode($reply);
        break;
    }
    return $reply;
  }

Any idea what's causing this?

mynetx commented 6 years ago

@GreenFootballs Sounds like $reply is not set when you enter the function?

GreenFootballs commented 6 years ago

Found the problem by inserting some debugging code. Twitter apparently changed the way they're handling the statuses_show_ID call. I was passing in an ID extracted from a Twitter URL, without stripping off any query string that was appended to it. Previously, this worked; maybe Twitter was using intval() or some other way to get just the integer part of the ID and it ignored the query string. But they must have changed this code, and now a query string after the ID causes the call to fail.

Anyway, it was an easy fix once I realized what the problem was.