mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-09 01:26:51 +00:00
Php 8.4 Will Deprecate fgetcsv Parameter
As described in issue #4161, Php seems to be prepared to break the fgetcsv function in release 9, marking the existing usage deprecated in 8.4. This gives us a long-term problem. This PR provides a short-term solution.
This commit is contained in:
@@ -228,11 +228,11 @@ class Csv extends BaseReader
|
||||
$delimiter = $this->delimiter ?? '';
|
||||
|
||||
// Loop through each line of the file in turn
|
||||
$rowData = fgetcsv($fileHandle, 0, $delimiter, $this->enclosure, $this->escapeCharacter);
|
||||
$rowData = self::getCsv($fileHandle, 0, $delimiter, $this->enclosure, $this->escapeCharacter);
|
||||
while (is_array($rowData)) {
|
||||
++$worksheetInfo[0]['totalRows'];
|
||||
$worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], count($rowData) - 1);
|
||||
$rowData = fgetcsv($fileHandle, 0, $delimiter, $this->enclosure, $this->escapeCharacter);
|
||||
$rowData = self::getCsv($fileHandle, 0, $delimiter, $this->enclosure, $this->escapeCharacter);
|
||||
}
|
||||
|
||||
$worksheetInfo[0]['lastColumnLetter'] = Coordinate::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex'] + 1);
|
||||
@@ -379,7 +379,7 @@ class Csv extends BaseReader
|
||||
|
||||
// Loop through each line of the file in turn
|
||||
$delimiter = $this->delimiter ?? '';
|
||||
$rowData = fgetcsv($fileHandle, 0, $delimiter, $this->enclosure, $this->escapeCharacter);
|
||||
$rowData = self::getCsv($fileHandle, 0, $delimiter, $this->enclosure, $this->escapeCharacter);
|
||||
$valueBinder = Cell::getValueBinder();
|
||||
$preserveBooleanString = method_exists($valueBinder, 'getBooleanConversion') && $valueBinder->getBooleanConversion();
|
||||
$this->getTrue = Calculation::getTRUE();
|
||||
@@ -416,7 +416,7 @@ class Csv extends BaseReader
|
||||
}
|
||||
++$columnLetter;
|
||||
}
|
||||
$rowData = fgetcsv($fileHandle, 0, $delimiter, $this->enclosure, $this->escapeCharacter);
|
||||
$rowData = self::getCsv($fileHandle, 0, $delimiter, $this->enclosure, $this->escapeCharacter);
|
||||
++$currentRow;
|
||||
}
|
||||
|
||||
@@ -649,4 +649,27 @@ class Csv extends BaseReader
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Php8.4 deprecates use of anything other than null string
|
||||
* as escape Character.
|
||||
*
|
||||
* @param resource $stream
|
||||
* @param null|int<0, max> $length
|
||||
*
|
||||
* @return array<int,?string>|false
|
||||
*/
|
||||
private static function getCsv(
|
||||
$stream,
|
||||
?int $length = null,
|
||||
string $separator = ',',
|
||||
string $enclosure = '"',
|
||||
string $escape = '\\'
|
||||
): array|false {
|
||||
if (PHP_VERSION_ID >= 80400 && $escape !== '') {
|
||||
return @fgetcsv($stream, $length, $separator, $enclosure, $escape);
|
||||
}
|
||||
|
||||
return fgetcsv($stream, $length, $separator, $enclosure, $escape);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user