diff --git a/src/PhpSpreadsheet/Shared/StringHelper.php b/src/PhpSpreadsheet/Shared/StringHelper.php index 323aff408f..34005e6017 100644 --- a/src/PhpSpreadsheet/Shared/StringHelper.php +++ b/src/PhpSpreadsheet/Shared/StringHelper.php @@ -722,4 +722,19 @@ public static function convertPostToString(string $index, string $default = ''): return $default; } + + /** + * Php introduced str_increment with Php8.3, + * but didn't issue deprecation notices till 8.5. + * + * @codeCoverageIgnore + */ + public static function stringIncrement(string &$str): void + { + if (function_exists('str_increment')) { + $str = str_increment($str); // @phpstan-ignore-line + } else { + ++$str; // @phpstan-ignore-line + } + } } diff --git a/src/PhpSpreadsheet/Writer/Html.php b/src/PhpSpreadsheet/Writer/Html.php index 2cdbd38679..fa558f45f5 100644 --- a/src/PhpSpreadsheet/Writer/Html.php +++ b/src/PhpSpreadsheet/Writer/Html.php @@ -571,7 +571,7 @@ public function generateSheetData(): string } ++$column; /** @var string $colStr */ - ++$colStr; + StringHelper::stringIncrement($colStr); } $html .= $this->generateRow($sheet, $rowData, $row - 1, $cellType); } @@ -941,7 +941,7 @@ private function buildCssPerSheet(Worksheet $sheet, array &$css): void if ($this->shouldGenerateColumn($sheet, $colStr)) { $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = self::DEFAULT_CELL_WIDTH_POINTS . 'pt'; } - ++$colStr; + StringHelper::stringIncrement($colStr); } // col elements, loop through columnDimensions and set width diff --git a/src/PhpSpreadsheet/Writer/Pdf/Dompdf.php b/src/PhpSpreadsheet/Writer/Pdf/Dompdf.php index 294e020c46..0c073c521f 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/Dompdf.php +++ b/src/PhpSpreadsheet/Writer/Pdf/Dompdf.php @@ -44,6 +44,13 @@ public function save($filename, int $flags = 0): void $orientation = ($orientation == 'L') ? 'landscape' : 'portrait'; // Create PDF + $restoreHandler = false; + if (PHP_VERSION_ID >= self::$temporaryVersionCheck) { + // @codeCoverageIgnoreStart + set_error_handler(self::specialErrorHandler(...)); + $restoreHandler = true; + // @codeCoverageIgnoreEnd + } $pdf = $this->createExternalWriterInstance(); $pdf->setPaper($paperSize, $orientation); @@ -53,6 +60,27 @@ public function save($filename, int $flags = 0): void // Write to file fwrite($fileHandle, $pdf->output() ?? ''); + if ($restoreHandler) { + restore_error_handler(); // @codeCoverageIgnore + } parent::restoreStateAfterSave(); } + + protected static int $temporaryVersionCheck = 80500; + + /** + * Temporary handler for Php8.5 waiting for Dompdf release. + * + * @codeCoverageIgnore + */ + public function specialErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool + { + if ($errno === E_DEPRECATED) { + if (preg_match('/canonical|imagedestroy/', $errstr) === 1) { + return true; + } + } + + return false; // continue error handling + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 79adbabc4e..11e115ad6d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,6 +6,9 @@ function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool { + if (strIncrement85(PHP_VERSION_ID, $errno, $errstr, $filename)) { + return true; // message suppressed - stop error handling + } $x = error_reporting() & $errno; if ( in_array( @@ -31,6 +34,21 @@ function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int return false; // continue error handling } +function strIncrement85(int $version, int $errno, string $errstr, string $filename): bool +{ + if ($version < 80500 || $errno !== E_DEPRECATED) { + return false; + } + if (preg_match('/Increment on non-numeric string/', $errstr) === 1) { + return true; + } + if (preg_match('/canonical/', $errstr) === 1 && preg_match('/mitoteam/', $filename) === 1) { + return true; + } + + return false; +} + if (!method_exists(PHPUnit\Framework\TestCase::class, 'setOutputCallback')) { set_error_handler('phpunit10ErrorHandler'); }