Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count(): Parameter must be an array or an object #1377

Closed
malohtie opened this issue Jan 25, 2018 · 7 comments
Closed

count(): Parameter must be an array or an object #1377

malohtie opened this issue Jan 25, 2018 · 7 comments
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@malohtie
Copy link

when i use this code

$service = new Google_Service_Urlshortener($client);              
$url = new Google_Service_Urlshortener_Url();
$url->setLongUrl($links);
$shortlink = $service->url->insert($url);

I got this warning

<p>Severity: Warning</p>
<p>Message:  count(): Parameter must be an array or an object that implements Countable</p>
<p>Filename: Handler/CurlFactory.php</p>
<p>Line Number: 67</p>

i think it only in php 7.2 was fine in 7.1

@ginc
Copy link

ginc commented Feb 5, 2018

Stack trace for the same issue:

GuzzleHttp\Handler\CurlFactory::release() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php, line 67
--
  | GuzzleHttp\Handler\CurlFactory::finish() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php, line 107
  | GuzzleHttp\Handler\CurlHandler::__invoke() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php, line 43
  | GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php, line 28
  | GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php, line 51
  | GuzzleHttp\PrepareBodyMiddleware::__invoke() - ROOT/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php, line 72
  | GuzzleHttp\Middleware::GuzzleHttp\{closure}() - ROOT/vendor/guzzlehttp/guzzle/src/Middleware.php, line 30
  | GuzzleHttp\RedirectMiddleware::__invoke() - ROOT/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php, line 68
  | GuzzleHttp\Middleware::GuzzleHttp\{closure}() - ROOT/vendor/guzzlehttp/guzzle/src/Middleware.php, line 57
  | GuzzleHttp\HandlerStack::__invoke() - ROOT/vendor/guzzlehttp/guzzle/src/HandlerStack.php, line 67
  | GuzzleHttp\Client::transfer() - ROOT/vendor/guzzlehttp/guzzle/src/Client.php, line 275
  | GuzzleHttp\Client::sendAsync() - ROOT/vendor/guzzlehttp/guzzle/src/Client.php, line 97
  | GuzzleHttp\Client::send() - ROOT/vendor/guzzlehttp/guzzle/src/Client.php, line 104
  | Google\Auth\HttpHandler\Guzzle6HttpHandler::__invoke() - ROOT/vendor/google/auth/src/HttpHandler/Guzzle6HttpHandler.php, line 34
  | Google\Auth\OAuth2::fetchAuthToken() - ROOT/vendor/google/auth/src/OAuth2.php, line 501
  | Google_Client::fetchAccessTokenWithAuthCode() - ROOT/vendor/google/apiclient/src/Google/Client.php, line 191

It seems that this issue has been already been solved in guzzle guzzle/guzzle#1686, however google api links to a specific version of guzzle which is older than the fix.

@mattwhisenhunt mattwhisenhunt added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed status: investigating labels Feb 5, 2018
@mattwhisenhunt mattwhisenhunt self-assigned this Feb 5, 2018
@LindaLawton
Copy link

LindaLawton commented Feb 7, 2018

try

   $shortlink = $service->url->insert("https://example.com");    

If that doesnt work try

   $optParams = array('fields' => '*');
   $shortlink = $service->url->insert("https://example.com",  $optParams);    

@nickaguilarh
Copy link

nickaguilarh commented Feb 27, 2018

Same type of error when using:

$client = new Google_Client(['client_id' => $CLIENT_ID]);
$payload = $client->verifyIdToken($id_token);

"count(): Parameter must be an array or an object that implements Countable"

@trobaniellu
Copy link

trobaniellu commented Mar 16, 2018

The problem is in PHP 7.2 the parameter for count() can't be NULL. The warning in the first post gets displayed when $this->handles equals NULL. Just replace line 67 in CurlFactory.php with the following:

if (($this->handles ? count($this->handles) : 0) >= $this->maxHandles) {

@mattwhisenhunt
Copy link
Contributor

Please try upgrading your version of Guzzle.

@LindaLawton
Copy link

LindaLawton commented Jun 18, 2018

Links to Can't quickstart with PHP for Google Analytics Note this is not my question i am just linking it here for documentation reasons.

@mxdpeep
Copy link

mxdpeep commented Jun 18, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

7 participants