-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fixes for PHP 8.2 in tcpdf_fonts.php - fixes #632 #633
Conversation
Fixes "use of "self" in callables is deprecated" warning is arising from tcpdf_fonts.php when using PHP >= 8.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if it breaks old PHP versions ?
We still support 5.4..
PHP 5.4... Wow. This should work down to PHP 5.5. I guess I'd have to write some sort of phpversion() check. Would that be OK? |
I checked composer.json it's even worse: 5.3 |
PHP 8.2 "use of "self" in callables is deprecated" yet some ways of fixing this breaks for PHP 5.3. This approach works, tested PHP 5.3.29 - 8.2.0
5.3! Gasp! 😋 I was able to test and confirm another approach (committed to #633) works using PHP 5.3.29 through 8.2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!!!
You removed one space before the argument, can you add it back?
Spaces added back in before arguments
Spaces done, I think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup look great
Please add |
Sorry - I've made a mistake. This fix doesn't work, and probably won't work without a phpversion() conditional and an include() to move code (self::class) which WILL break 5.3 to another file. PHP 5.5 is as low as the "easy fix" goes. Awkward! Hopefully other ideas roll in. |
Is there only 5.3 that is broken? |
This fix starts working with PHP 5.5. It seems it'd be a bit of an ordeal to make it work 5.3-8.2 because of these callables. Do-able but not pretty! |
Interestingly, PHP 5.3 EOL was almost exactly ten years ago: 14 Aug 2014 😳 Edit: Today felt like 2024. |
😳😨 Can it be a variable and replaced if version compare === old? |
5.3 parses everything before run and when it sees self::class, it breaks. |
If I am not mistaken |
self::class is a string but 5.3 sees that :: in the file and 😵 Something like this might work:
I'm testing now. |
I meant that is you var_dump(self::class) you will get it's final form ;) |
Sure, TCPDF_Fonts. Have you tried what you're suggesting? |
Hmm, sorry I got confused in my brain So with a version compare it can be changed between |
Because writing self::class anywhere in a file called by TCPDF (such as tcpdf_fonts.php) will break PHP 5.3. Similar to how using array() notation [] in a PHP 5.3 file will break it. The other solution I've mentioned with include() is much more complicated, and involves checking for PHP > 8.2, and including a separate file conditionally which isn't seen by 5.3 at all.
Using get_called_class() (like I did above) is the simplest solution I've found that works. I'll do some more testing here to make sure. |
I think when I've begun coding about nuts I've lost my mind. 🥜🧠 Will test this a bit more and update the PR! |
I agree, that said you do not need to write self::class but only it's final form and it will work great too |
Using something like 'TCPDF_FONTS::uniord' would work in older versions of PHP but not newer versions 🤷♀️ It stopped working with PHP 8. I'm glad you like the get_called_class() solution well enough 😊 |
Maneuvers compatibility of callables inside array_map() between PHP 5.3 and 8.2 - tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for your hard work !
You are welcome! I've been using this library since well... PHP 5.3, so it's the least I can do to finally jump in on Github and help. 👵🏼 |
So cool! |
Hi I tested the proposed fixe under PHP 8.2.9 x86 (in preparation to use TCPDF in PHP 8.3) I've reported the 3 new lines in tcpdf_fonts.php, and removed the old 3 existing ones, but I obtain that Deprecated: Optional parameter $isunicode declared before required parameter $currentfont is implicitly treated as a required parameter in .\tcpdf\include\tcpdf_fonts.php on line 2000, and 2027, 2043, etc... Also $setbom, $forcertl, $str, $default_css, $tagvs, etc... deprecated (perhaps due to the first deprecated) Is there something I've done wrong ? |
Fixes "use of "self" in callables is deprecated" warning is arising from tcpdf_fonts.php when using PHP >= 8.2