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

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

我刚刚将我的 phpexcel 更新为 phpspreadsheet,我注意到弹出此错误:

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

require 'Classes/PHPExcel.php';

这是触发上述错误的部分代码:

文件: 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.');
        }
 

文件: 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
}

文件: app/Http/Controllers/analyticsAuth/statement.old.php

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

文件: 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).');
}

谢谢

这可以通过将花括号 {} 替换为方括号 []

来解决

我想感谢 @HeySora 发表评论并指出了此特定案例中的确切问题。

在 php 7 中不再使用 $mode{0}。它已被弃用。而不是使用这个 $mode[0]