? ? Pending

User tests: Successful: Unsuccessful:

avatar alexandreelise
alexandreelise
26 Sep 2021

Pull Request for Issue #35674 .

Summary of Changes

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

Testing Instructions

Use PHP8.0.11
Enable captcha for Joomla 4.0.3 core contact form
Go to the contact form

Actual result BEFORE applying this Pull Request

Fatal error: Unknown named property $id

Expected result AFTER applying this Pull Request

The captcha shows up without error

Documentation Changes Required

I don't think so.

avatar alexandreelise alexandreelise - open - 26 Sep 2021
avatar alexandreelise alexandreelise - change - 26 Sep 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 26 Sep 2021
Category Libraries
avatar zero-24 zero-24 - change - 26 Sep 2021
Title
Fix issue #35674
Causing issue in PHP8.0.11 due to BC break in PHP8.0 regarding call_user_func_array and named parameters
avatar zero-24 zero-24 - edited - 26 Sep 2021
avatar PhilETaylor
PhilETaylor - comment - 26 Sep 2021

related to related to #33529 which is the same issue.

avatar alexandreelise
alexandreelise - comment - 26 Sep 2021

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!

avatar alexandreelise
alexandreelise - comment - 27 Sep 2021

Thanks George @wilsonge . I am sad that I missed your presentation about Joomla! 4 Web Services at JUG NJ I hope it was recorded. Take care Super Joomler.

avatar alexandreelise
alexandreelise - comment - 4 Oct 2021

Can someone please test this manually ? Maybe @alikon @bembelimen @chmst

avatar alikon
alikon - comment - 5 Oct 2021

didn't have PHP8.0.11 yet , but it looks good to me

avatar alexandreelise
alexandreelise - comment - 5 Oct 2021

Thanks @alikon This pull request needs Human Test Results. It's required. Do you someone who can test this manually with patchtester?

avatar joomdonation
joomdonation - comment - 14 Oct 2021

@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.

avatar alexandreelise
alexandreelise - comment - 14 Oct 2021

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.

avatar joomdonation
joomdonation - comment - 15 Oct 2021

@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.

avatar alexandreelise
alexandreelise - comment - 15 Oct 2021

@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

avatar PhilETaylor
PhilETaylor - comment - 15 Oct 2021

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.

avatar PhilETaylor
PhilETaylor - comment - 15 Oct 2021

I have tested this item successfully on 690e52b


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/35675.

avatar PhilETaylor PhilETaylor - test_item - 15 Oct 2021 - Tested successfully
avatar alexandreelise
alexandreelise - comment - 15 Oct 2021

Thanks for clarifying the situation @PhilETaylor indeed you already reported a similar related issue

avatar pmleconte pmleconte - test_item - 13 Nov 2021 - Tested successfully
avatar pmleconte
pmleconte - comment - 13 Nov 2021

I have tested this item successfully on 690e52b


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/35675.

avatar richard67 richard67 - change - 13 Nov 2021
Status Pending Ready to Commit
Labels Added: ?
avatar richard67
richard67 - comment - 13 Nov 2021

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/35675.

avatar HLeithner HLeithner - change - 13 Nov 2021
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: ?
avatar HLeithner HLeithner - close - 13 Nov 2021
avatar HLeithner HLeithner - merge - 13 Nov 2021
avatar HLeithner
HLeithner - comment - 13 Nov 2021

Thanks

avatar alexandreelise
alexandreelise - comment - 13 Nov 2021

Thanks to all super joomlers contributing back to the Joomla! project. Have a great day.

Add a Comment

Login with GitHub to post a comment