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

Write function throws deprecated error if fed null value #582

Open DesBarnard opened 1 year ago

DesBarnard commented 1 year ago

A depricated error message is thrown from line 6383 of tcpdf.php if the $txt fed to the function is NULL (quite possible if being fed from a database that allows null values in the relevant field). Own copy fixed by modifying to "if ($txt == NULL || strlen($txt) == 0) {"

williamdes commented 1 year ago

What is the full stack trace for this error or the function name ?

DesBarnard commented 1 year ago

Error reported:- Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/awcc/public_html/members/tcpdf/tcpdf.php on line 6383

tcpdf.php version 6.6.2 PHP version 8.1.14

williamdes commented 1 year ago

I think your fix can be committed, it is a valid one even if the type passed to Write should be a string.

- if (strlen($txt) == 0) { 
+ if ($txt === null || strlen($txt) === 0) { 

https://github.com/tecnickcom/TCPDF/blob/2fb1c01bc37487d1f94fe1297f8d8ad1b5c290bb/tcpdf.php#L6383