Skip to content

Commit 481cef2

Browse files
authored
Php8.2 Deprecation in Reader/Xlsx (#2894)
* Php8.2 Deprecation in Reader/Xlsx Using `${var}` will be deprecated, with the suggested resolution being to use `{$var}`. This appears to be the only place in PhpSpreadsheet which does this. Some vendor packages will need to change for 8.2 for this and other reasons. * mb_convert_encoding and HTML_ENTITIES Also scheduled to be deprecated with 8.2. It appears to have not been needed in PhpSpreadsheet in the first place.
1 parent 1829dea commit 481cef2

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -632,16 +632,6 @@ protected function processDomElement(DOMNode $element, Worksheet $sheet, int &$r
632632
}
633633
}
634634

635-
/**
636-
* Make sure mb_convert_encoding returns string.
637-
*
638-
* @param mixed $result
639-
*/
640-
private static function ensureString($result): string
641-
{
642-
return is_string($result) ? $result : '';
643-
}
644-
645635
/**
646636
* Loads PhpSpreadsheet from file into PhpSpreadsheet instance.
647637
*
@@ -660,8 +650,8 @@ public function loadIntoExisting($filename, Spreadsheet $spreadsheet)
660650
$dom = new DOMDocument();
661651
// Reload the HTML file into the DOM object
662652
try {
663-
$convert = mb_convert_encoding($this->securityScanner->scanFile($filename), 'HTML-ENTITIES', 'UTF-8');
664-
$loaded = $dom->loadHTML(self::ensureString($convert));
653+
$convert = $this->securityScanner->scanFile($filename);
654+
$loaded = $dom->loadHTML($convert);
665655
} catch (Throwable $e) {
666656
$loaded = false;
667657
}
@@ -683,8 +673,8 @@ public function loadFromString($content, ?Spreadsheet $spreadsheet = null): Spre
683673
$dom = new DOMDocument();
684674
// Reload the HTML file into the DOM object
685675
try {
686-
$convert = mb_convert_encoding($this->securityScanner->scan($content), 'HTML-ENTITIES', 'UTF-8');
687-
$loaded = $dom->loadHTML(self::ensureString($convert));
676+
$convert = $this->securityScanner->scan($content);
677+
$loaded = $dom->loadHTML($convert);
688678
} catch (Throwable $e) {
689679
$loaded = false;
690680
}

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
414414
[$workbookBasename, $xmlNamespaceBase] = $this->getWorkbookBaseName();
415415
$drawingNS = self::REL_TO_DRAWING[$xmlNamespaceBase] ?? Namespaces::DRAWINGML;
416416
$chartNS = self::REL_TO_CHART[$xmlNamespaceBase] ?? Namespaces::CHART;
417-
$wbRels = $this->loadZip("xl/_rels/${workbookBasename}.rels", Namespaces::RELATIONSHIPS);
417+
$wbRels = $this->loadZip("xl/_rels/{$workbookBasename}.rels", Namespaces::RELATIONSHIPS);
418418
$theme = null;
419419
$this->styleReader = new Styles();
420420
foreach ($wbRels->Relationship as $relx) {
@@ -1849,11 +1849,6 @@ private static function getArrayItem($array, $key = 0)
18491849

18501850
private static function dirAdd($base, $add): string
18511851
{
1852-
$add = "$add";
1853-
if (substr($add, 0, 4) === '/xl/') {
1854-
$add = substr($add, 4);
1855-
}
1856-
18571852
return (string) preg_replace('~[^/]+/\.\./~', '', dirname($base) . "/$add");
18581853
}
18591854

0 commit comments

Comments
 (0)