I’ve been working to update a ZF3 application from php 7.1 to go to php 7.4 and switched over to the Laminas project. I ran across some errors in our unit tests that pointed me to this piece of code in ResultSet::Initialize()
if (is_array($dataSource)) {
// its safe to get numbers from an array
$first = current($dataSource);
reset($dataSource);
$this->fieldCount = $first === false ? 0 : count($first);
Consider a dataSource of:
$dataSource = [0 = ‘12345’]
$first will be ‘12345’, and generate an error as that is not a countable object.
Consider a dataSource of:
$dataSource = [0 => [‘1’ => ‘123’, ‘2’ => '123]]
$first will get count() of 2, setting $fieldCount to 2, when the actual value should be 1.
The fix is simple count the $dataSource, not $first:
$this->fieldCount = $first === false ? 0 : count($dataSource);
Best Regards,
Jeff Davis