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

Fix PHP8.2 str_split function returns empty arrays for empty strings #588

Open HuongNV13 opened 1 year ago

HuongNV13 commented 1 year ago

In PHP 8.2, the str_split function will returns empty arrays for empty strings. See: https://php.watch/versions/8.2/str_split-empty-string-empty-array

We can use mb_str_split() instead

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

fooman commented 1 year ago

Unfortunately mb_str_split() was only introduced in php7.4 which will make swapping this out trickier.

williamdes commented 1 year ago

Unfortunately mb_str_split() was only introduced in php7.4 which will make swapping this out trickier.

Thanks for the hint! Okay, some code needs to be added and use PHP_MAJOR_VERSION const and it's friends

williamdes commented 1 year ago

or maybe just function_exists()

HuongNV13 commented 1 year ago

Thanks, everyone. I have updated the code to use function_exists() to use the correct method.

MacGritsch commented 1 year ago

I think this is not a valid fix as mb_str_split() behaves the same way as str_split() in PHP 8.2 and above. So why dont check if its an empty string (and if its needed in that case). Otherwise you could also write a function str_split_old() which returns array('') if the input string is empty.

nicolaasuni commented 5 months ago

Please try to resolve the conflicts. Could you please instead create a wrapper function in tcpdf_static.php?

HuongNV13 commented 5 months ago

Hi Nicola, Sorry for the late reply, I was busy with my project. I will update the patch soon.

Thanks,