Skip to content

Commit e73fc33

Browse files
committed
Temporary Workaround for Mpdf Php8.5 Deprecation
1 parent 996de17 commit e73fc33

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/PhpSpreadsheet/Writer/Pdf/Mpdf.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public function save($filename, int $flags = 0): void
4040

4141
// Create PDF
4242
$config = ['tempDir' => $this->tempDir . '/mpdf'];
43+
$restoreHandler = false;
44+
if (PHP_VERSION_ID >= self::$temporaryVersionCheck) {
45+
// @codeCoverageIgnoreStart
46+
set_error_handler(self::specialErrorHandler(...));
47+
$restoreHandler = true;
48+
// @codeCoverageIgnoreEnd
49+
}
4350
$pdf = $this->createExternalWriterInstance($config);
4451
$ortmp = $orientation;
4552
$pdf->_setPageSize($paperSize, $ortmp);
@@ -83,9 +90,30 @@ public function save($filename, int $flags = 0): void
8390
$str = $pdf->Output('', 'S');
8491
fwrite($fileHandle, $str);
8592

93+
if ($restoreHandler) {
94+
restore_error_handler(); // @codeCoverageIgnore
95+
}
8696
parent::restoreStateAfterSave();
8797
}
8898

99+
protected static int $temporaryVersionCheck = 80500;
100+
101+
/**
102+
* Temporary handler for Php8.5 waiting for Dompdf release.
103+
*
104+
* @codeCoverageIgnore
105+
*/
106+
public function specialErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
107+
{
108+
if ($errno === E_DEPRECATED) {
109+
if (preg_match('/Providing an empty string is deprecated/', $errstr) === 1) {
110+
return true;
111+
}
112+
}
113+
114+
return false; // continue error handling
115+
}
116+
89117
/**
90118
* Convert inches to mm.
91119
*/

0 commit comments

Comments
 (0)