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

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

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

Body:

Introduction

Since upgrading to PHPSpreadsheet, you might have encountered the following error message: "ErrorException (E_DEPRECATED) - Array and string offset access syntax with curly braces is deprecated." The issue occurs due to a subtle difference in how PHPExcel and PHPSpreadsheet handle certain file operations. In this comprehensive blog post, we'll discuss the underlying causes of this error and provide possible solutions to overcome it.

Causes & Solutions for Error in PHPExcel Files

  1. Deprecated syntax: The deprecation warning is triggered due to the usage of curly braces in accessing array elements and strings. In PHPExcel, these curly braces are often used with string offsets (e.g., $var{0}, $path{0}) or array keys (e.g., $array['key1']). In PHPSpreadsheet, you should use a dot instead of curly braces for array access (e.g., $array['key1']), and concatenation methods for string indexing.

  2. Register functions: You may encounter an error where PHPSpreadsheet cannot locate the registered autoloader or a specific function, causing issues with file loading or class instantiation. To resolve this, ensure that all necessary files are included in your project and that you have correctly installed PHPSpreadsheet using Composer if applicable. For example, include require_once 'PHPExcel/Autoloader.php'; and check the dependencies mentioned in the readme document.

  3. Unsupported modes: The mode argument (e.g., $mode{0} != 'r') can be another reason for your error message. In PHPSpreadsheet, only the read-only access mode is supported; thus, ensure that you pass 'r' as the mode parameter when opening files in PHPSpreadsheet.

  4. Autoloader registration: The PHPExcel autoloader may be registered twice or incorrectly. This causes a conflict and results in errors during your application execution. To prevent this issue, include PHPExcel_Autoloader::Register(); and PHPExcel_Shared_ZipStreamWrapper::register(); only once.

  5. Disabling multibyte function overloading: In PHPExcel, the ini_get function checks for mbstring.func_overload & 2 to ensure that multibyte function overloading needs to be disabled for string functions (function 2). This requirement may cause errors in your application when using other libraries that handle strings differently. To resolve this issue, you can comment out the line if (ini_get('mbstring.func_overload') & 2) { or update your project code to adhere to the new PHPSpreadsheet requirements.

Conclusion

By understanding the underlying causes and following the provided solutions, you can successfully address the "Array and string offset access syntax with curly braces is deprecated" error while working with PHPExcel and PHPSpreadsheet. To learn more about PHPSpreadsheet and best practices for development, explore our resources at https://laravelcompany.com.