From 11612e6aeca17b0e8bf46a87335fc19f5df568b0 Mon Sep 17 00:00:00 2001 From: Olivier <42406745+olivier-idlab@users.noreply.github.com> Date: Wed, 15 Aug 2018 15:51:57 +0200 Subject: [PATCH] Avoid E_NOTICE and E_WARNING in PHP 7.1 Since PHP 7.1, E_NOTICE and E_WARNING are produced if unexpected characters are found when implicitly converting a string to value. Columns with relative width now produce errors when used in arithmetic operations. A workaround is to explicitly cast string to value before doing arithmetic operations. See https://wiki.php.net/rfc/invalid_strings_in_arithmetic --- lib/PHPPdf/Core/Node/Table.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/PHPPdf/Core/Node/Table.php b/lib/PHPPdf/Core/Node/Table.php index b695caf0..a5d83c1f 100644 --- a/lib/PHPPdf/Core/Node/Table.php +++ b/lib/PHPPdf/Core/Node/Table.php @@ -75,28 +75,28 @@ private function setColumnWidthIfNecessary(Node $node) $colspan = $node->getAttribute('colspan'); $isWidthRelative = strpos($width, '%') !== false; + $width = (float) $width; $currentWidth = 0; for($i=0; $i<$colspan; $i++) { $realColumnNumber = $columnNumber + $i; - $currentWidth += isset($this->widthsOfColumns[$realColumnNumber]) ? $this->widthsOfColumns[$realColumnNumber] : 0; + $currentWidth += isset($this->widthsOfColumns[$realColumnNumber]) ? (float) $this->widthsOfColumns[$realColumnNumber] : 0; } - + $diff = ($width - $currentWidth)/$colspan; - - if($isWidthRelative) - { - $diff .= '%'; - } if($diff >= 0) { for($i=0; $i<$colspan; $i++) { $realColumnNumber = $columnNumber + $i; - - $this->widthsOfColumns[$realColumnNumber] = isset($this->widthsOfColumns[$realColumnNumber]) ? ($this->widthsOfColumns[$realColumnNumber] + $diff) : $diff; + $widthOfColumn = (isset($this->widthsOfColumns[$realColumnNumber]) ? ((float) $this->widthsOfColumns[$realColumnNumber]) : 0) + $diff; + if($isWidthRelative) + { + $widthOfColumn .= '%'; + } + $this->widthsOfColumns[$realColumnNumber] = $widthOfColumn; } } } @@ -254,4 +254,4 @@ public function reduceColumnsWidthsByMargins() $this->widthsOfColumns[$columnNumber] -= $marginsLeft[$columnNumber] + $marginsRight[$columnNumber]; } } -} \ No newline at end of file +}