0

I am using phpspreadsheet in my project which works fine on localhost but when I migrated to production server, it is throwing following error :

PHP Parse error:  syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) in 

/httpdocs/Test/excelTest/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php on line 209\n'

I have checked the other related question/answers which suggests the PHP Version issue. I am using PHP 5.6 at my Local while the Production server has 5.4. I cannot upgrade the PHP version of production server as it is hosted on a shared hosting.

So is there anything else that can be done to get over this issue?

Related Code :

require 'vendor/autoload.php';

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

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello  asjdghkjhsdfsdh World !');
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 5, 'PhpSpreadsheet');

$writer = new Xlsx($spreadsheet);
$writer->save('hello_world.xlsx');
Amit Singh
  • 2,267
  • 4
  • 25
  • 50

1 Answers1

1

According to the documentation of phpspreadsheet (https://phpspreadsheet.readthedocs.io/en/develop/#software-requirements)

Software requirements

The following software is required to develop using PhpSpreadsheet:

PHP version 5.6 or newer

So I think the answer is that you cannot use this on a server running PHP 5.4.

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55