13

I've just updated my phpexcel to phpspreadsheet, and I noticed this error pops up:

ErrorException (E_DEPRECATED) Array and string offset access syntax with curly braces is deprecated

require 'Classes/PHPExcel.php';

here is part of my code which is triggering the above error:

File: project/public/Classes/PHPExcel/Shared/ZipStreamWrapper.php

  public function stream_open($path, $mode, $options, &$opened_path)
    {
        // Check for mode
        if ($mode{0} != 'r') { //Error Line
            throw new PHPExcel_Reader_Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
        }
 

File: project/public/Classes/PHPExcel.php

/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
    define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
    require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); //Error Line
}

File: app/Http/Controllers/analyticsAuth/statement.old.php

use PHPExcel_Reader_Excel2007;
use PHPExcel; 
use PHPExcel_IOFactory;
use ZipArchive;
require 'Classes/PHPExcel.php'; //Error Line

File: project/public/Classes/PHPExcel/Autoloader.php

PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register(); //Error Line
if (ini_get('mbstring.func_overload') & 2) {
    throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}

Thank you

11
  • You probably need your require to be before the other use statements. Are you sure Classes/PHPExcel.php exists? If you replace require with include and the error goes away, it means the file can't be found. Commented Aug 27, 2020 at 8:22
  • @HeySora, I haven't removed PHPExcel yet. Commented Aug 27, 2020 at 8:46
  • But I'm trying to Migrate from phpexcel to phpspreadsheet. Commented Aug 27, 2020 at 8:47
  • 1
    Thanks for adding the actual error to your question. An E_DEPRECATED error means some piece of code used to be valid in a previous PHP version, but isn't valid anymore. You should have details under the error in order to locate the file name as well as the line number. Commented Aug 27, 2020 at 8:48
  • @HeySora, I've added detailed of the following Error. Commented Aug 27, 2020 at 8:58

2 Answers 2

15

This can be fix by replacing the curly braces {} with square brackets []

I would like to give credit to the @HeySora who made the comment and pointed out the exact issue in this particular case.

Sign up to request clarification or add additional context in comments.

2 Comments

Where had you changed the bracket? Can you share the code?
Everyone should be advised that PHPExcel is a DEAD repository and project and the code is depricated and not being maintained in any way at all. Do not attempt to try and update it, it is a fool's errand. Easier Instead to consider using PhpSpreadsheet, which is a fine replacement. I was able to only change several lines of code where I just point to it instead of the PhpExcell in my code, and also I just replaced PhpExcell's wording with PhpSpreadsheets version of that, and viola! code worked fine. Also use PhpSpreadsheets instruction to install it. works fine using composer.
5

This is not longer in use $mode{0} in php 7. it has been deprecated. Instead of using that use this $mode[0]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.