User tests: Successful: Unsuccessful:
Pull Request for Issue #35674 .
Fix issue in Captcha causing a Fatal error in PHP8.0 due to B/C break in PHP8.0 regarding call_user_func_array and named properties
#35674 (comment)
Added array_values around $params to prevent breaking change behaviour when using assoc arrays and named properties in call_user_func_array in PHP 8.0.11
Use PHP8.0.11
Enable captcha for Joomla 4.0.3 core contact form
Go to the contact form
Fatal error: Unknown named property $id
The captcha shows up without error
I don't think so.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Title |
|
Thanks @PhilETaylor for helping Joomla! being PHP8.0 compliant. When I see that PHP8.1 should come out in november and we need to do that again. Hopefully it won't break that much since it's a minor version PHP8.1. Take care you all Super Joomlers!
Can someone please test this manually ? Maybe @alikon @bembelimen @chmst
didn't have PHP8.0.11 yet , but it looks good to me
@alexandreelise I'm using PHP 8.0.1 (on Windows), Joomla 4 nightly build and could not see the fatal error as you mentioned. Captcha still displays OK for me. Tested with both the captcha plugins come with Joomla.
Hi @joomdonation. Thanks for your feedback.
There might be at least 2 reasons for that You are using a different PHP version, you are using nightly joomla build, I'm using the official 4.0.3 at the time I was writing this. And one last reason that i can think of, is that I didn't mention that I am talking about the hcaptcha plugin not the builtin recaptcha one. But both of these plugins use the same Captcha class where there is the "bug" I found. Anyway can you share the code lines of your install we are talking about in this pr just where the bug is? I suspect we don't have the same setup or that it has been fixed in the nightly build maybe with another PR. Who knows.
Take care Super Joomler. Have a great day.
@alexandreelise I actually used 8.0.11 (not 8.0.1 as I wrote before, just a typo). I had a quick look at the hcaptcha plugin and the real reason which causes this error is from that plugin. The init method of that plugin is defined as below:
public function onInit()
{
// If there is no Public Key set, then this plugin is no use, so exit
if ($this->params->get('publicKey', '') === '')
{
throw new \RuntimeException(Text::_('PLG_CAPTCHA_HCAPTCHA_ERROR_NO_PUBLIC_KEY'));
}
// Load the JavaScript from hCaptcha
HTMLHelper::_('script', 'https://hcaptcha.com/1/api.js', ['version' => 'auto', 'relative' => true], ['defer' => 'defer', 'async' => 'async']);
return true;
}
It does not have $id parameter (like our core captcha plugins) as expected by the system. Your PR should solve the issue, but I'm unsure if we should make this change or should the developer of this plugin fixes his code.
With that said, I will wait for feedback from others before doing real test for your PR.
@joomdonation There is really a breaking change in PHP8 and I didn't invent it. Here is the official php.net documentation talking about call_user_func_array breaking change in PHP8 highlighted link in the official documentation
call_user_func_array() array keys will now be interpreted as parameter names, instead of being silently ignored.
The root issue is the new PHP 8 feature called Named Parameters. Its the same root issue as #33529 issue.
The simple fix is to use a non-keyed array - you can do that using the array_values()
fix
The "more correct" fix is to modernise the code to ensure that it takes into account PHP 8 features, including Named Parameters, although there seems little appetite for that in the Joomla code base.
Your PR should solve the issue, but I'm unsure if we should make this change or should the developer of this plugin fixes his code.
Or we can stop telling 3pd to fix their stuff - again, like we did in #33529, and implement a more bullet proof solution in Joomla which is simple to remove calls to call_user_func* functions or, pass those functions a non-keyed array by using the array_values()
fix to strip the keys.
I have tested this item
Thanks for clarifying the situation @PhilETaylor indeed you already reported a similar related issue
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
Labels |
Added:
?
|
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-11-13 20:10:54 |
Closed_By | ⇒ | HLeithner | |
Labels |
Added:
?
|
Thanks
Thanks to all super joomlers contributing back to the Joomla! project. Have a great day.
related to related to #33529 which is the same issue.