PHPExcel Error: Array and string offset access syntax with curly braces is deprecated

32,812

Solution 1

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.

Solution 2

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

Share:
32,812
Maqsud
Author by

Maqsud

Updated on February 03, 2022

Comments

  • Maqsud
    Maqsud over 2 years

    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

  • user9437856
    user9437856 over 3 years
    Where had you changed the bracket? Can you share the code?