From de332dba065ca74d4dc12245c171e28700f11528 Mon Sep 17 00:00:00 2001 From: Bruno Farias Date: Wed, 6 Sep 2023 10:03:03 +0200 Subject: [PATCH] php 8+ edge cases fixes (#630) Co-authored-by: Nicola Asuni --- include/tcpdf_static.php | 4 ++-- tcpdf.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/tcpdf_static.php b/include/tcpdf_static.php index 57006552..81805054 100644 --- a/include/tcpdf_static.php +++ b/include/tcpdf_static.php @@ -1780,7 +1780,7 @@ public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $f if ($ret === false) { return array(); } - return $ret; + return is_array($ret) ? $ret : array(); } // preg_split is bugged - try alternative solution $ret = array(); @@ -2124,7 +2124,7 @@ public static function _freadint($f) { * Array of page formats * measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4) * @public static - * + * * @var array */ public static $page_formats = array( diff --git a/tcpdf.php b/tcpdf.php index 688a985b..25a00d67 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -6409,7 +6409,7 @@ public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $st // calculate maximum width for a single character on string $chrw = $this->GetArrStringWidth($chars, '', '', 0, true); array_walk($chrw, array($this, 'getRawCharWidth')); - $maxchwidth = max($chrw); + $maxchwidth = ((is_array($chrw) || $chrw instanceof Countable) && count($chrw) > 0) ? max($chrw) : 0; // get array of chars $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode); // get the number of characters @@ -6872,6 +6872,8 @@ protected function fitBlock($w, $h, $x, $y, $fitonpage=false) { } // resize the block to be contained on the remaining available page or column space if ($fitonpage) { + // fallback to avoid division by zero + $h = $h == 0 ? 1 : $h; $ratio_wh = ($w / $h); if (($y + $h) > $this->PageBreakTrigger) { $h = $this->PageBreakTrigger - $y;