TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in call_flow_summary (xml_cdr.php)

bayden10

New Member
Oct 2, 2016
19
0
1
Canada
www.icttech.net
Description:
When viewing CDR details and call flow in the FusionPBX UI, the following fatal error occurs:

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/www/fusionpbx/app/xml_cdr/resources/classes/xml_cdr.php:1449
Stack trace:
#0 /var/www/fusionpbx/app/xml_cdr/xml_cdr_details.php(285): xml_cdr->call_flow_summary()
#1 {main}
thrown in /var/www/fusionpbx/app/xml_cdr/resources/classes/xml_cdr.php on line 1449

Steps to Reproduce:
  1. Import CDRs (all call_flow fields are valid JSON arrays, e.g. '[]').
  2. Click on a CDR to view details and call flow.
  3. Observe the fatal error.
What I’ve Checked:
  • All call_flow values in the database are valid JSON arrays ('[]'), not NULL.
  • No other fields (json, xml) are NULL.
  • The error persists even with clean, valid data.
Root Cause:The code in call_flow_summary() (in xml_cdr.php) calls count() on a variable that may be null or not an array, without checking its type. This causes a TypeError in PHP 7.2+ (and is strictly enforced in PHP 8.0+).

Suggested Fix:
Add a type check before calling count(), for example:

$call_flow = json_decode($row['call_flow'], true);
$count = is_array($call_flow) ? count($call_flow) : 0;

or wherever count() is used:

count($value)

Should be:

is_array($value) ? count($value) : 0

Request:
Please update the code to include this type check to prevent fatal errors when call_flow is null or not an array.

Environment:
  • FusionPBX version: 5.3.8
  • PHP version: 8.1
  • Database: PostgreSQL
Thank you for your attention to this issue!
~b10