PHP nightly: The parameter must be an array or an object that implements Countable

I see UT errors in PHP webapp running in Travis CI against PHP nightly:

$ php --version
PHP 7.2.0-dev (cli) (built: Dec  4 2016 22:49:34) ( ZTS )

This is a failed test case:

$payments = PaymentsHelper::refunds('DE0000000001', '2016-04-01', '2017-04-01');

$this->assertNotNull($payments);
$this->assertEquals(0, count($payments));

Test Failure

1) PaymentsHelperTest::test_refunds_within_lifetime
count(): Parameter must be an array or an object that implements Countable

The code we are checking currently contains debugging logs showing that the return value is refunds()indeed an array:

Array
(
    [0] => Payment Object
        (
...
        )
)

Am I finding a bug in PHP at night?

+4
source share
2 answers

I debugged the problem again and realized that the error occurs earlier in the code, where the dependency returns NULLand the code calls count(NULL):

$bonds = $bond_factory->find_all(/* ... */);
if (count($bonds) > 0)
{
  //...
}

count() :

$bonds = $bond_factory->find_all(/* ... */);
if (!is_null($bonds) && count($bonds) > 0)
{
  //...
}

PHP 7.2.0-dev .

+3

.

if ( count( $bonds ? : [] ) ) { .... }
0

Source: https://habr.com/ru/post/1662854/


All Articles