Question

After updating from 2.3.5p2 to 2.4.1 and from php 7.1 to php 7.4 I have strange trouble with request parameters.

I see, that there are parameters set, when I var_dump

$parameters=$this->request->getParams();

var_dump($parameters);

Output:

array(5) { ["key"]=> string(64) "4e10c465f6988a7fjdueia57dbac2407f7990206d27eb47d531c5a94311ca51fd" ["namespace"]=> string(10) "importgrid" ["filters"]=> array(1) { ["placeholder"]=> string(4) "true" } ["paging"]=> array(2) { ["pageSize"]=> string(2) "20" ["current"]=> string(1) "1" } ["isAjax"]=> string(4) "true" } 

I can also access $parameters["key"]; but every other value gives me an error:

var_dump($parameters["paging"]);

Notice: Undefined index: paging in .....

Its like those array keys dont exist, even they show up in the dump $parameters... Any ideas, what is happening here? Have I missed something big in php-arrays from 7.1 to 7.4?

Was it helpful?

Solution

As usual, I came back to answer the question myself.

The problem is, that you can't declare an null value to a variable with php 7.4. You can handle it by setting a condition:

if (isset($this->request->getParam('sorting')['field'])) {
  $field=$this->request->getParam('sorting')['field'];
}
else {
  $field="id";
}

Same goes for direction, pagesize and current page.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top