tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.18k stars 1.51k forks source link

Error on php >= 8.x Unsupported operand types: string * float #504

Open morrning opened 2 years ago

morrning commented 2 years ago

in vendor/tecnickcom/tcpdf/tcpdf.php (line 3504) when run addpage function run with error: *Unsupported operand types: string float* but i can fix that with replace of code with this and define variable type for $headerdata['logo_width'] in lines 3500 - 3504 `// set starting margin for text data cell if ($this->getRTL()) { $header_x = $this->original_rMargin + ((float)$headerdata['logo_width'] 1.1); } else { $header_x = $this->original_lMargin + ((float)$headerdata['logo_width'] 1.1); } $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ((float)$headerdata['logo_width'] 1.1); `

nalfonsin commented 2 years ago

I have the same problem with PHP 8.1.4, @morrning maybe a slightly cleaner solution would be:

// quick fix :)
class TCPDF {

  // line 3337
  public function setHeaderData($ln='', $lw=0, $ht='', $hs='', $tc=array(0,0,0), $lc=array(0,0,0)) {
    $this->header_logo = $ln;
    $this->header_logo_width = (int) $lw;
    $this->header_title = $ht;
    $this->header_string = $hs;
    $this->header_text_color = $tc;
    $this->header_line_color = $lc;
  }

  // line 3364
  public function getHeaderData() {
    $ret = array();
    $ret['logo'] = $this->header_logo;
    $ret['logo_width'] = (int) $this->header_logo_width;
    $ret['title'] = $this->header_title;
    $ret['string'] = $this->header_string;
    $ret['text_color'] = $this->header_text_color;
    $ret['line_color'] = $this->header_line_color;
    return $ret;
  }

}