Skip to content

Commit 54b81a1

Browse files
authored
String Increment Deprecated in Php8.5 - r222 (#4603)
1 parent 4594396 commit 54b81a1

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

src/PhpSpreadsheet/Shared/StringHelper.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,4 +647,19 @@ public static function testStringAsNumeric(string $textValue): float|string
647647

648648
return (is_numeric(substr($textValue, 0, strlen((string) $v)))) ? $v : $textValue;
649649
}
650+
651+
/**
652+
* Php introduced str_increment with Php8.3,
653+
* but didn't issue deprecation notices till 8.5.
654+
*
655+
* @codeCoverageIgnore
656+
*/
657+
public static function stringIncrement(string &$str): void
658+
{
659+
if (function_exists('str_increment')) {
660+
$str = str_increment($str);
661+
} else {
662+
++$str;
663+
}
664+
}
650665
}

src/PhpSpreadsheet/Writer/Html.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ public function generateSheetData(): string
502502
$rowData[$column] = ($sheet->getCellCollection()->has($cellAddress)) ? $cellAddress : '';
503503
}
504504
++$column;
505-
++$colStr;
505+
StringHelper::stringIncrement($colStr);
506506
}
507507
$html .= $this->generateRow($sheet, $rowData, $row - 1, $cellType);
508508
}
@@ -860,7 +860,7 @@ private function buildCssPerSheet(Worksheet $sheet, array &$css): void
860860
if ($this->shouldGenerateColumn($sheet, $colStr)) {
861861
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = self::DEFAULT_CELL_WIDTH_POINTS . 'pt';
862862
}
863-
++$colStr;
863+
StringHelper::stringIncrement($colStr);
864864
}
865865

866866
// col elements, loop through columnDimensions and set width

src/PhpSpreadsheet/Writer/Pdf/Dompdf.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public function save($filename, int $flags = 0): void
4444
$orientation = ($orientation == 'L') ? 'landscape' : 'portrait';
4545

4646
// Create PDF
47+
$restoreHandler = false;
48+
if (PHP_VERSION_ID >= self::$temporaryVersionCheck) {
49+
// @codeCoverageIgnoreStart
50+
set_error_handler(self::specialErrorHandler(...));
51+
$restoreHandler = true;
52+
// @codeCoverageIgnoreEnd
53+
}
4754
$pdf = $this->createExternalWriterInstance();
4855
$pdf->setPaper($paperSize, $orientation);
4956

@@ -53,6 +60,27 @@ public function save($filename, int $flags = 0): void
5360
// Write to file
5461
fwrite($fileHandle, $pdf->output() ?? '');
5562

63+
if ($restoreHandler) {
64+
restore_error_handler(); // @codeCoverageIgnore
65+
}
5666
parent::restoreStateAfterSave();
5767
}
68+
69+
protected static int $temporaryVersionCheck = 80500;
70+
71+
/**
72+
* Temporary handler for Php8.5 waiting for Dompdf release.
73+
*
74+
* @codeCoverageIgnore
75+
*/
76+
public function specialErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
77+
{
78+
if ($errno === E_DEPRECATED) {
79+
if (preg_match('/canonical|imagedestroy/', $errstr) === 1) {
80+
return true;
81+
}
82+
}
83+
84+
return false; // continue error handling
85+
}
5886
}

tests/bootstrap.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
88
{
9+
if (strIncrement85(PHP_VERSION_ID, $errno, $errstr, $filename)) {
10+
return true; // message suppressed - stop error handling
11+
}
912
$x = error_reporting() & $errno;
1013
if (
1114
in_array(
@@ -31,6 +34,21 @@ function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int
3134
return false; // continue error handling
3235
}
3336

37+
function strIncrement85(int $version, int $errno, string $errstr, string $filename): bool
38+
{
39+
if ($version < 80500 || $errno !== E_DEPRECATED) {
40+
return false;
41+
}
42+
if (preg_match('/Increment on non-numeric string/', $errstr) === 1) {
43+
return true;
44+
}
45+
if (preg_match('/canonical/', $errstr) === 1 && preg_match('/mitoteam/', $filename) === 1) {
46+
return true;
47+
}
48+
49+
return false;
50+
}
51+
3452
if (!method_exists(PHPUnit\Framework\TestCase::class, 'setOutputCallback')) {
3553
ini_set('error_reporting', (string) E_ALL);
3654
set_error_handler('phpunit10ErrorHandler');

0 commit comments

Comments
 (0)