@@ -228,11 +228,11 @@ public function listWorksheetInfo(string $filename): array
228
228
$ delimiter = $ this ->delimiter ?? '' ;
229
229
230
230
// Loop through each line of the file in turn
231
- $ rowData = fgetcsv ($ fileHandle , 0 , $ delimiter , $ this ->enclosure , $ this ->escapeCharacter );
231
+ $ rowData = self :: getCsv ($ fileHandle , 0 , $ delimiter , $ this ->enclosure , $ this ->escapeCharacter );
232
232
while (is_array ($ rowData )) {
233
233
++$ worksheetInfo [0 ]['totalRows ' ];
234
234
$ worksheetInfo [0 ]['lastColumnIndex ' ] = max ($ worksheetInfo [0 ]['lastColumnIndex ' ], count ($ rowData ) - 1 );
235
- $ rowData = fgetcsv ($ fileHandle , 0 , $ delimiter , $ this ->enclosure , $ this ->escapeCharacter );
235
+ $ rowData = self :: getCsv ($ fileHandle , 0 , $ delimiter , $ this ->enclosure , $ this ->escapeCharacter );
236
236
}
237
237
238
238
$ worksheetInfo [0 ]['lastColumnLetter ' ] = Coordinate::stringFromColumnIndex ($ worksheetInfo [0 ]['lastColumnIndex ' ] + 1 );
@@ -379,7 +379,7 @@ private function loadStringOrFile(string $filename, Spreadsheet $spreadsheet, bo
379
379
380
380
// Loop through each line of the file in turn
381
381
$ delimiter = $ this ->delimiter ?? '' ;
382
- $ rowData = fgetcsv ($ fileHandle , 0 , $ delimiter , $ this ->enclosure , $ this ->escapeCharacter );
382
+ $ rowData = self :: getCsv ($ fileHandle , 0 , $ delimiter , $ this ->enclosure , $ this ->escapeCharacter );
383
383
$ valueBinder = Cell::getValueBinder ();
384
384
$ preserveBooleanString = method_exists ($ valueBinder , 'getBooleanConversion ' ) && $ valueBinder ->getBooleanConversion ();
385
385
$ this ->getTrue = Calculation::getTRUE ();
@@ -416,7 +416,7 @@ private function loadStringOrFile(string $filename, Spreadsheet $spreadsheet, bo
416
416
}
417
417
++$ columnLetter ;
418
418
}
419
- $ rowData = fgetcsv ($ fileHandle , 0 , $ delimiter , $ this ->enclosure , $ this ->escapeCharacter );
419
+ $ rowData = self :: getCsv ($ fileHandle , 0 , $ delimiter , $ this ->enclosure , $ this ->escapeCharacter );
420
420
++$ currentRow ;
421
421
}
422
422
@@ -649,4 +649,27 @@ public function setSheetNameIsFileName(bool $sheetNameIsFileName): self
649
649
650
650
return $ this ;
651
651
}
652
+
653
+ /**
654
+ * Php8.4 deprecates use of anything other than null string
655
+ * as escape Character.
656
+ *
657
+ * @param resource $stream
658
+ * @param null|int<0, max> $length
659
+ *
660
+ * @return array<int,?string>|false
661
+ */
662
+ private static function getCsv (
663
+ $ stream ,
664
+ ?int $ length = null ,
665
+ string $ separator = ', ' ,
666
+ string $ enclosure = '" ' ,
667
+ string $ escape = '\\'
668
+ ): array |false {
669
+ if (PHP_VERSION_ID >= 80400 && $ escape !== '' ) {
670
+ return @fgetcsv ($ stream , $ length , $ separator , $ enclosure , $ escape );
671
+ }
672
+
673
+ return fgetcsv ($ stream , $ length , $ separator , $ enclosure , $ escape );
674
+ }
652
675
}
0 commit comments