Fix count() on NULL

Created on 16 October 2023, about 1 year ago
Updated 17 October 2023, about 1 year ago

Problem/Motivation

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

Proposed resolution

diff --git a/src/PHPExcel.php b/src/PHPExcel.php
index 9024a6e..7f7ef54 100644
--- a/src/PHPExcel.php
+++ b/src/PHPExcel.php
@@ -428,8 +428,8 @@ not set to TRUE. Excel export aborted.");
// if the file is built in multiple passes.
$offset = $sheet->getHighestRow() + ($options['ignore_headers'] ? 0 : 1);

- for ($i = 0, $len = count($sheet_data); $i < $len; $i++) {
- for ($j = 0; $j < count($sheet_data[$i]); $j++) {
+ for ($i = 0, $len = count((array) $sheet_data); $i < $len; $i++) {
+ for ($j = 0; $j < count((array) $sheet_data[$i]); $j++) {
$value = $sheet_data[$i][$j] ?? '';

// We must offset the row count (by 2 if the first row is used by the

🐛 Bug report
Status

Needs review

Version

4.0

Component

Code

Created by

🇫🇷France aymen.essid

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024