TCPDF icon indicating copy to clipboard operation
TCPDF copied to clipboard

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

Open HuongNV13 opened this issue 2 years ago • 10 comments

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

HuongNV13 avatar Feb 03 '23 07:02 HuongNV13

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Feb 03 '23 08:02 CLAassistant

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

fooman avatar Feb 10 '23 03:02 fooman

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 avatar Feb 10 '23 11:02 williamdes

or maybe just function_exists()

williamdes avatar Feb 10 '23 11:02 williamdes

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

HuongNV13 avatar Feb 13 '23 03:02 HuongNV13

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.

MacGritsch avatar May 11 '23 09:05 MacGritsch

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

nicolaasuni avatar Apr 20 '24 17:04 nicolaasuni

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

Thanks,

HuongNV13 avatar Apr 24 '24 13:04 HuongNV13