PHPExcel错误:不建议使用带有花括号的数组和字符串偏移量访问语法

问题描述

我刚刚将phpexcel更新为phpspreadsheet,我发现此错误弹出:

ErrorException(E_DEPRECATED) 不建议使用带有花括号的数组和字符串偏移量访问语法

需要“ 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]

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...