Search code examples
phparrayshighchartsphp-8

Uncaught TypeError: join(): Argument #2 ($array) must be of type ?array, string given / PHP8 data for highcharts


My webhost changed the PHP Version from PHP7.4 to PHP8. Now my Highcharts are not shown anymore and I got an error message depending to the Highcharts series data.

The data for the chart comes from a mysql database.

This is the error:

Uncaught TypeError: join(): Argument #2 ($array) must be of type ?array, string given in testchart.php:64
Stack trace:
\#0 testchart.php(64): join(Array, ',')
\#1 {main}
thrown in testchart.php on line 64

My call of join():

data: [<?php echo join($tempA24, ',') ?>],

This is the array with the database values:


array(2) {
  [0] => array(2) {
    [0] => float(1667131200000)[1] => float(21)
  }
  [1] => array(2) {
    [0] => float(1667134800000)[1] => float(22)
  }
}

Solution

  • The syntax for join is the other way round - it should be join($separator, $array)

    Or, in your case: join(',', $tempA24);

    As for the reason it used to work - there was a legacy signature taking the arguments the other way around. However, this was deprecated in PHP 7.4, and has now been removed in PHP 8.0

    Docs (join is a direct alias of implode):

    implode(string $separator, array $array): string

    Legacy signature (deprecated as of PHP 7.4.0, removed as of PHP 8.0.0):
    implode(array $array, string $separator): string