• Fatal error: Array and string offset access syntax with curly braces is no longer supported in /wp-content/plugins/advanced-cf7-db/admin/class/PHPExcel/Shared/String.php on line 529

    BR,
    Maciej

Viewing 2 replies - 1 through 2 (of 2 total)
  • Quick solution, until it may be resolved by the plugin author in the next update:

    Replace the six occurances of $str{...} with $str[...] in the function utf16_decode() after line 527 of /wp-content/plugins/advanced-cf7-db/admin/class/PHPExcel/Shared/String.php
    (Tip: make a copy/backup of that file before changing it)

    Or if you don’t want to pick each occurance, just replace the whole function with

    
    	public static function utf16_decode($str, $bom_be = TRUE) {
    		if( strlen($str) < 2 ) return $str;
    		$c0 = ord($str[0]);
    		$c1 = ord($str[1]);
    		if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
    		elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
    		$len = strlen($str);
    		$newstr = '';
    		for($i=0;$i<$len;$i+=2) {
    			if( $bom_be ) { $val = ord($str[$i])   << 4; $val += ord($str[$i+1]); }
    			else {        $val = ord($str[$i+1]) << 4; $val += ord($str[$i]); }
    			$newstr .= ($val == 0x228) ? "\n" : chr($val);
    		}
    		return $newstr;
    	}
    

    A little background, esp. for the plugin author @vsourz1td :
    The “offset access syntax with curly braces” was deprecated in PHP 7.4, see https://wiki.php.net/rfc/deprecate_curly_braces_array_access

    Advanced Contact form 7 DB uses the library PHPExcel to create Excel files. PHPExcel is deprecated since 2017, and should be replaced by PhpSpreadsheet.
    See https://github.com/PHPOffice/PHPExcel
    and https://github.com/PHPOffice/PhpSpreadsheet (“Do you need to migrate? There is an automated tool for that.”)

    Edit: this topic is a duplicate of
    https://www.ads-software.com/support/topic/export-to-excel-error-2/
    https://www.ads-software.com/support/topic/advanced-cf7-and-php-8-0/
    https://www.ads-software.com/support/topic/php8-pdf-and-excel-failed/
    etc, but no answer or solution there

    • This reply was modified 2 years, 6 months ago by cyrfer. Reason: duplicate topics mentioned

    For me this didn’t work, I had to change way more files in PHPExcel that use curly brace indexing.

    So I used PHP Rector to refactor the entire library:
    composer require rector/rector –dev

    modify rector.php:
    use Rector\Php74\Rector\ArrayDimFetch\CurlyToSquareBracketArrayStringRector;
    //register a single rule
    $rectorConfig->rule(CurlyToSquareBracketArrayStringRector::class);

    run:
    vendor/bin/rector process .\wp-content\plugins\advanced-cf7-db\admin

    [OK] 18 files have been changed by Rector

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fatal Error exporting XLS’ is closed to new replies.