stripe/stripe-php

count() Throws Fatal Error in 8.2

hipwebdesign opened this issue · 2 comments

Describe the bug

PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, stdClass given in /var/www/composer/vendor/stripe/stripe-php/lib/HttpClient/CurlClient.php:219

The constructRequest function counts parameters, but the parameters are passed as an object which is "uncountable" in PHP 8.2.

To Reproduce

Using php 8.2, try retrieving a product:

$product = $stripeClient->product->retrieve($product_id,[]);

Expected behavior

Expected a product to be returned without error.

Code snippets

No response

OS

Linux

PHP version

PHP 8.2

Library version

stripe-php v10.21.0

API version

2023-08-16

Additional context

No response

Hello @hipwebdesign. We were unable to reproduce this failure case with

$product = $stripe->products->retrieve("prod_xyz", []);

or with any invocation of this method that looks like what we expect. Can you provide the exact code you are calling that produces this error? I suspect you might be calling the method like

$product = $stripe->products->retrieve("prod_xyz", \json_decode("{}"));

which will result in a class instance being passed to ->retrieve instead of an array as the method expects, whereas

$product = $stripe->products->retrieve("prod_xyz", \json_decode("{}", TRUE));

would decode to an associative array which is countable.

@richardm-stripe I was mistaken as to which request was causing the error. I believe I was sending a standard class object to the all endpoint, like this:

$product = $stripe->invoices->all($stdClass);

At any rate, standard class objects are not countable is 8.2, so I suppose this is not a bug.