TCPDF icon indicating copy to clipboard operation
TCPDF copied to clipboard

Warning: Trying to access array offset on value of type null in ...\tcpdf.php on line 2468

Open BrainforgeUK opened this issue 3 years ago • 6 comments

Cannot generate output due to ... TCPDF ERROR: Some data has already been output, can't send PDF file

Solution I implemented using a class override ... ` public function getCellHeight($fontsize, $padding=TRUE) {

	$height = ($fontsize * $this->cell_height_ratio);

	if ($padding && !empty($this->cell_padding) {
		$height += ($this->cell_padding['T'] + $this->cell_padding['B']);
	}
	return round($height, 6);
}

`

BrainforgeUK avatar Nov 19 '22 13:11 BrainforgeUK

@BrainforgeUK Could you provide an example of code generating this error ?

jausions avatar Nov 30 '22 06:11 jausions

I don't know how it got into the state where $this->cell_padding = null

This is one of a number of occassions where earlier versions would silently ignore the error, and it is often benign anyway - maybe in this instance a value of 0 would be assumed.

PHP 7.4 and 8 are less forgiving and the unexpected / 'this will never happen' has to be coded for! - such as here.

BrainforgeUK avatar Nov 30 '22 10:11 BrainforgeUK

I can confirm that I had the same issue as of PHP 7.4 onwards, using TCPDF v6.6.2 The suggested fix did resolve it for me as well - I have tested on both PHP 7.4 and PHP 8.1

@BrainforgeUK - your example is missing a close bracket BTW ;)

@jausions - The errors would be something like the attached screenshot. Screenshot from 2023-05-15 12-01-00

So the full function should maybe look something like this:

public function getCellHeight($fontsize, $padding=TRUE) { $height = ($fontsize * $this->cell_height_ratio); if ($padding && !empty($this->cell_padding)) { $height += ($this->cell_padding['T'] + $this->cell_padding['B']); } return round($height, 6); }

Hope this helps!

kosmro avatar May 15 '23 02:05 kosmro

Thanks @kosmro Could you open a pull-request request here to fix this?

williamdes avatar May 15 '23 09:05 williamdes

Thanks @kosmro Could you open a pull-request request here to fix this?

I'll look into it tonight :)

kosmro avatar May 16 '23 00:05 kosmro

Can you close this issue ? 6.6.3 is out and #620 is merged

williamdes avatar Sep 06 '23 14:09 williamdes