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 [].
new Input([]) initialized with []
new Input([]) generates an object initialized with a different source.
Joomla 4.
As a workaround, to create an empty Input, the developer could call a new Input(['no-input' => 'fake-input'])...
| Labels |
Removed:
?
|
||
| Labels |
Added:
No Code Attached Yet
|
||
Or better with positive logic and simplified using null coalescing: $this->data = $source ?? $_REQUEST;
Yes, it would be better with the Null Coalescing Operator.
@richard67 Do you submit the PR? Or, do I submit the change?
@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?
| Status | New | ⇒ | Closed |
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-11-13 09:51:46 |
| Closed_By | ⇒ | joomdonation |
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.
Would it be a solution to replace the
empty($source)by!isset($source)?