No Code Attached Yet
avatar anibalsanchez
anibalsanchez
4 Oct 2021

Steps to reproduce the issue

Checking the Joomla\Input\Input class, the constructor is defined in this way:

	public function __construct($source = null, array $options = [])
	{
		$this->data    = empty($source) ? $_REQUEST : $source;
		$this->filter  = $options['filter'] ?? new Filter\InputFilter;
		$this->options = $options;
	}

As a consequence, a call to new Input([]) generates an Input initialized with the $_REQUEST, instead of generating an Input initialized with [].

According to the doc:

@param   array  $source   Optional source data. If omitted, a copy of the server variable '_REQUEST' is used.

Since the parameter $source is not committed, and it has the value [], the object should be initialized with [].

Expected result

new Input([]) initialized with []

Actual result

new Input([]) generates an object initialized with a different source.

System information (as much as possible)

Joomla 4.

Additional comments

As a workaround, to create an empty Input, the developer could call a new Input(['no-input' => 'fake-input'])...

avatar anibalsanchez anibalsanchez - open - 4 Oct 2021
avatar anibalsanchez anibalsanchez - change - 4 Oct 2021
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 4 Oct 2021
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 4 Oct 2021
avatar richard67
richard67 - comment - 4 Oct 2021

Would it be a solution to replace the empty($source)by !isset($source)?

avatar richard67
richard67 - comment - 4 Oct 2021

Or better with positive logic and simplified using null coalescing: $this->data = $source ?? $_REQUEST;

avatar anibalsanchez
anibalsanchez - comment - 5 Oct 2021

Yes, it would be better with the Null Coalescing Operator.

avatar anibalsanchez
anibalsanchez - comment - 8 Oct 2021

@richard67 Do you submit the PR? Or, do I submit the change?

avatar richard67
richard67 - comment - 8 Oct 2021

@anibalsanchez If you want, do it. It could take some time until I can do it, so I'd be happy if you can be faster. Do you have any idea about testing instructions, how we can test that nothing is broken?

avatar joomdonation joomdonation - change - 13 Nov 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-11-13 09:51:46
Closed_By joomdonation
avatar joomdonation joomdonation - close - 13 Nov 2022
avatar joomdonation
joomdonation - comment - 13 Nov 2022

Look like the issue was sorted already. The current code is:

$this->data = $source ?? $_REQUEST;

It is already addressed the issue reported here, so I'm closing this issue.

Add a Comment

Login with GitHub to post a comment