1

After switching to PHP 7 I'm getting "ERR (3): Notice: Array to string conversion" thousands of times in my system log. I've got most everything else working fairly smoothly but for some reason I'm having some difficulties wrapping my head around what the method that's erroring is actually trying to do. I know the script aims to sort css & javascript and the method is sorting the scripts.

If I understand the goal I can probably rewrite it. The issue is, the method seems counter intuitive to me:

public function getCssJsHtml()
    {
        foreach ($this->_data['items'] as $itemKey => $itemValue) {
            $sortedItems[$itemKey] = $itemValue['sort'];
        }
        array_multisort($sortedItems, SORT_NUMERIC, $this->_data['items']);
        array_multisort($this->_data['items'], SORT_STRING, $sortedItems);

        return parent::getCssJsHtml();
    }

The actual line that is throwing the error is:

array_multisort($this->_data['items'], SORT_STRING, $sortedItems);

it looks like the first line is sorting the $sortedItems array by it's numeric value (sort order):

array_multisort($sortedItems, SORT_NUMERIC, $this->_data['items']);

But then the next line appears to reverse the effects by putting it back into the original _data['items'] array now sorted by string? Therefor rendering the line above it useless and throwing the error that brought it to my attention in the first place?

Error is thrown because it's treating an array like a string?

2
  • Where is this getCssJsHtml function defined ? In which file ? Commented Apr 25, 2017 at 14:22
  • @RaphaelatDigitalPianism It's defined in the community tree. "/app/code/community/Namespace/Sortcssjs/Block/Page/Html/Head.php" Commented Apr 25, 2017 at 15:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.