Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BrainforgeUK opened this issue Nov 19, 2022 · 6 comments

Comments

@BrainforgeUK
Copy link

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);
}

`

@jausions
Copy link
Contributor

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

@BrainforgeUK
Copy link
Author

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.

@kosmro
Copy link
Contributor

kosmro commented May 15, 2023

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!

@williamdes
Copy link
Contributor

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

@kosmro
Copy link
Contributor

kosmro commented May 16, 2023

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

I'll look into it tonight :)

kosmro added a commit to kosmro/TCPDF that referenced this issue May 16, 2023
Tested and confirmed working in PHP 7.4 and PHP 8.2
nicolaasuni pushed a commit that referenced this issue Sep 6, 2023
Tested and confirmed working in PHP 7.4 and PHP 8.2
@williamdes
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants