0

I am getting error is :

Parse error: syntax error, unexpected '=' in D:\services\traincard\PHPspreadsheet\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Calculation\Calculation.php on line 2470

My code :

// include composer autoload
require '../PHPspreadsheet/vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

$sheet->setCellValue('A1', 'Hello World !'); 
$sheet->setCellValue('B1', 'ทดสอบข้อความภาษาไทย !'); 

$writer = new Xlsx($spreadsheet);
$output_file = "hello_world.xlsx"; 
$writer->save($output_file); 

if(file_exists($output_file)){ 
    echo '<a href="'.$output_file.'" target="_blank">Download</a>';
}

I downloaded PHPspreadsheet from https://php-download.com/package/phpoffice/phpspreadsheet My PHP version is 5.6 So I downloaded PHPspreadsheet 1.8.2 It's get this error. So I downloaded version 1.8.0. It still the same. Why? How do i fix it?

Meawmill
  • 67
  • 1
  • 13

1 Answers1

1

The error is occurring on this line in the library:

[$language] = explode('_', $locale);

This is array destructuring, and it's new in PHP 7.1. It's equivalent to:

list($language) = explode('_', $locale);
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thank you.I edited on every line. But it have the new error. error show "syntax error, unexpected '?' (on line 3589)" So I looked that line it's "$itemStoreKey = $d['storeKey'] ?? null;" What's < ?? null > ? I never knew that.... How do I fix it? @Barmar – Meawmill Apr 07 '20 at 06:58
  • https://riptutorial.com/php/example/7164/null-coalescing-operator----- – Barmar Apr 07 '20 at 07:00
  • You're going to drive yourself crazy. This library obviously requires PHP 7.1, you're can't use it in 5.6. – Barmar Apr 07 '20 at 07:00
  • OK... I give up!! I think I 'm really crazy hahaha. Back to use PHPexcel... Thank you. @Barmar – Meawmill Apr 07 '20 at 09:29