Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ArgumentCountError: array_merge_recursive() #1402

Merged
merged 1 commit into from
Jul 6, 2021

Conversation

Flyingmana
Copy link
Contributor

@Flyingmana Flyingmana commented Jan 18, 2021

fix ArgumentCountError: array_merge_recursive() does not accept unknown
named parameters

Description (*)

On a Product containing swatches (with Demo Data: /men/shirts/plaid-cotton-shirt-473.html ) on PHP8

appears the following error:

Uncaught ArgumentCountError: array_merge_recursive() does not accept unknown named parameters in 
/var/www/html/src/htdocs/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php:346 Stack trace: #0

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes OpenMage/magento-lts#<issue_number>

Manual testing scenarios (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

fix ArgumentCountError: array_merge_recursive() does not accept unknown
named parameters
@github-actions github-actions bot added the Component: ConfigurableSwatches Relates to Mage_ConfigurableSwatches label Jan 18, 2021
@Flyingmana Flyingmana added the PHP 8 Related to PHP8 label Jan 18, 2021
@S0FTWEX
Copy link
Contributor

S0FTWEX commented Mar 25, 2021

Using array_values in this case is not good solution. It causes notices and warnings just like this:

Notice: Undefined index: labels in /app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php on line 347
Warning: array_unique() expects parameter 1 to be array, null given in /app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php on line 347
Warning: array_map(): Expected parameter 2 to be an array, null given in /app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php on line 350
Warning: array_merge(): Expected parameter 1 to be an array, null given in /app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php on line 350
Warning: in_array() expects parameter 2 to be array, null given in /app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php on line 356

Another solution/workaround of this case is needed.

@@ -343,7 +343,7 @@ public function filterImageInGallery($product, $image)
}

if (!isset($this->_productImageFilters[$product->getId()])) {
$mapping = call_user_func_array("array_merge_recursive", $product->getChildAttributeLabelMapping());
$mapping = call_user_func_array("array_merge_recursive", array_values($product->getChildAttributeLabelMapping()));
$filters = array_unique($mapping['labels']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice: Undefined index: labels in /app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php on line 347

@Flyingmana
Copy link
Contributor Author

I tested it with a product from the sample data.

'$product->getChildAttributeLabelMapping()':

array(9) {
  ["charcoal"]=>
  array(4) {
    ["product_ids"]=>
    array(5) {
      [0]=>
      string(3) "237"
      [1]=>
      string(3) "238"
      [2]=>
      string(3) "239"
      [3]=>
      string(3) "503"
      [4]=>
      string(3) "502"
    }
    ["label"]=>
    string(8) "charcoal"
    ["default_label"]=>
    string(8) "charcoal"
    ["labels"]=>
    array(2) {
      [0]=>
      string(8) "charcoal"
      [1]=>
      string(8) "charcoal"
    }
  }
  ["khaki"]=>
  array(4) {
    ["product_ids"]=>
    array(3) {
      [0]=>
      string(3) "897"
      [1]=>
      string(3) "898"
      [2]=>
      string(3) "899"
    }
    ["label"]=>
    string(5) "khaki"
    ["default_label"]=>
    string(5) "khaki"
    ["labels"]=>
    array(2) {
      [0]=>
      string(5) "khaki"
      [1]=>
      string(5) "khaki"
    }
  }
  ["red"]=>
  array(4) {
    ["product_ids"]=>
    array(3) {
      [0]=>
      string(3) "900"
      [1]=>
      string(3) "901"
      [2]=>
      string(3) "902"
    }
    ["label"]=>
    string(3) "red"
    ["default_label"]=>
    string(3) "red"
    ["labels"]=>
    array(2) {
      [0]=>
      string(3) "red"
      [1]=>
      string(3) "red"
    }
  }
  ["royal blue"]=>
  array(4) {
    ["product_ids"]=>
    array(3) {
      [0]=>
      string(3) "903"
      [1]=>
      string(3) "904"
      [2]=>
      string(3) "905"
    }
    ["label"]=>
    string(10) "royal blue"
    ["default_label"]=>
    string(10) "royal blue"
    ["labels"]=>
    array(2) {
      [0]=>
      string(10) "royal blue"
      [1]=>
      string(10) "royal blue"
    }
  }
  ["s"]=>
  array(4) {
    ["product_ids"]=>
    array(4) {
      [0]=>
      string(3) "237"
      [1]=>
      string(3) "897"
      [2]=>
      string(3) "900"
      [3]=>
      string(3) "903"
    }
    ["label"]=>
    string(1) "s"
    ["default_label"]=>
    string(1) "s"
    ["labels"]=>
    array(2) {
      [0]=>
      string(1) "s"
      [1]=>
      string(1) "s"
    }
  }
  ["m"]=>
  array(4) {
    ["product_ids"]=>
    array(4) {
      [0]=>
      string(3) "238"
      [1]=>
      string(3) "898"
      [2]=>
      string(3) "901"
      [3]=>
      string(3) "904"
    }
    ["label"]=>
    string(1) "m"
    ["default_label"]=>
    string(1) "m"
    ["labels"]=>
    array(2) {
      [0]=>
      string(1) "m"
      [1]=>
      string(1) "m"
    }
  }
  ["l"]=>
  array(4) {
    ["product_ids"]=>
    array(4) {
      [0]=>
      string(3) "239"
      [1]=>
      string(3) "899"
      [2]=>
      string(3) "902"
      [3]=>
      string(3) "905"
    }
    ["label"]=>
    string(1) "l"
    ["default_label"]=>
    string(1) "l"
    ["labels"]=>
    array(2) {
      [0]=>
      string(1) "l"
      [1]=>
      string(1) "l"
    }
  }
  ["xs"]=>
  array(4) {
    ["product_ids"]=>
    array(1) {
      [0]=>
      string(3) "503"
    }
    ["label"]=>
    string(2) "xs"
    ["default_label"]=>
    string(2) "xs"
    ["labels"]=>
    array(2) {
      [0]=>
      string(2) "xs"
      [1]=>
      string(2) "xs"
    }
  }
  ["xl"]=>
  array(4) {
    ["product_ids"]=>
    array(1) {
      [0]=>
      string(3) "502"
    }
    ["label"]=>
    string(2) "xl"
    ["default_label"]=>
    string(2) "xl"
    ["labels"]=>
    array(2) {
      [0]=>
      string(2) "xl"
      [1]=>
      string(2) "xl"
    }
  }
}

array_values($product->getChildAttributeLabelMapping()):

array(9) {
  [0]=>
  array(4) {
    ["product_ids"]=>
    array(5) {
      [0]=>
      string(3) "237"
      [1]=>
      string(3) "238"
      [2]=>
      string(3) "239"
      [3]=>
      string(3) "503"
      [4]=>
      string(3) "502"
    }
    ["label"]=>
    string(8) "charcoal"
    ["default_label"]=>
    string(8) "charcoal"
    ["labels"]=>
    array(2) {
      [0]=>
      string(8) "charcoal"
      [1]=>
      string(8) "charcoal"
    }
  }
  [1]=>
  array(4) {
    ["product_ids"]=>
    array(3) {
      [0]=>
      string(3) "897"
      [1]=>
      string(3) "898"
      [2]=>
      string(3) "899"
    }
    ["label"]=>
    string(5) "khaki"
    ["default_label"]=>
    string(5) "khaki"
    ["labels"]=>
    array(2) {
      [0]=>
      string(5) "khaki"
      [1]=>
      string(5) "khaki"
    }
  }
  [2]=>
  array(4) {
    ["product_ids"]=>
    array(3) {
      [0]=>
      string(3) "900"
      [1]=>
      string(3) "901"
      [2]=>
      string(3) "902"
    }
    ["label"]=>
    string(3) "red"
    ["default_label"]=>
    string(3) "red"
    ["labels"]=>
    array(2) {
      [0]=>
      string(3) "red"
      [1]=>
      string(3) "red"
    }
  }
  [3]=>
  array(4) {
    ["product_ids"]=>
    array(3) {
      [0]=>
      string(3) "903"
      [1]=>
      string(3) "904"
      [2]=>
      string(3) "905"
    }
    ["label"]=>
    string(10) "royal blue"
    ["default_label"]=>
    string(10) "royal blue"
    ["labels"]=>
    array(2) {
      [0]=>
      string(10) "royal blue"
      [1]=>
      string(10) "royal blue"
    }
  }
  [4]=>
  array(4) {
    ["product_ids"]=>
    array(4) {
      [0]=>
      string(3) "237"
      [1]=>
      string(3) "897"
      [2]=>
      string(3) "900"
      [3]=>
      string(3) "903"
    }
    ["label"]=>
    string(1) "s"
    ["default_label"]=>
    string(1) "s"
    ["labels"]=>
    array(2) {
      [0]=>
      string(1) "s"
      [1]=>
      string(1) "s"
    }
  }
  [5]=>
  array(4) {
    ["product_ids"]=>
    array(4) {
      [0]=>
      string(3) "238"
      [1]=>
      string(3) "898"
      [2]=>
      string(3) "901"
      [3]=>
      string(3) "904"
    }
    ["label"]=>
    string(1) "m"
    ["default_label"]=>
    string(1) "m"
    ["labels"]=>
    array(2) {
      [0]=>
      string(1) "m"
      [1]=>
      string(1) "m"
    }
  }
  [6]=>
  array(4) {
    ["product_ids"]=>
    array(4) {
      [0]=>
      string(3) "239"
      [1]=>
      string(3) "899"
      [2]=>
      string(3) "902"
      [3]=>
      string(3) "905"
    }
    ["label"]=>
    string(1) "l"
    ["default_label"]=>
    string(1) "l"
    ["labels"]=>
    array(2) {
      [0]=>
      string(1) "l"
      [1]=>
      string(1) "l"
    }
  }
  [7]=>
  array(4) {
    ["product_ids"]=>
    array(1) {
      [0]=>
      string(3) "503"
    }
    ["label"]=>
    string(2) "xs"
    ["default_label"]=>
    string(2) "xs"
    ["labels"]=>
    array(2) {
      [0]=>
      string(2) "xs"
      [1]=>
      string(2) "xs"
    }
  }
  [8]=>
  array(4) {
    ["product_ids"]=>
    array(1) {
      [0]=>
      string(3) "502"
    }
    ["label"]=>
    string(2) "xl"
    ["default_label"]=>
    string(2) "xl"
    ["labels"]=>
    array(2) {
      [0]=>
      string(2) "xl"
      [1]=>
      string(2) "xl"
    }
  }
}

The only difference is in the first level array keys as you see.
The result of call_user_func_array("array_merge_recursive", array_values($product->getChildAttributeLabelMapping())):


array(4) {
  ["product_ids"]=>
  array(28) {
    [0]=>
    string(3) "237"
    [1]=>
    string(3) "238"
    [2]=>
    string(3) "239"
    [3]=>
    string(3) "503"
    [4]=>
    string(3) "502"
    [5]=>
    string(3) "897"
    [6]=>
    string(3) "898"
    [7]=>
    string(3) "899"
    [8]=>
    string(3) "900"
    [9]=>
    string(3) "901"
    [10]=>
    string(3) "902"
    [11]=>
    string(3) "903"
    [12]=>
    string(3) "904"
    [13]=>
    string(3) "905"
    [14]=>
    string(3) "237"
    [15]=>
    string(3) "897"
    [16]=>
    string(3) "900"
    [17]=>
    string(3) "903"
    [18]=>
    string(3) "238"
    [19]=>
    string(3) "898"
    [20]=>
    string(3) "901"
    [21]=>
    string(3) "904"
    [22]=>
    string(3) "239"
    [23]=>
    string(3) "899"
    [24]=>
    string(3) "902"
    [25]=>
    string(3) "905"
    [26]=>
    string(3) "503"
    [27]=>
    string(3) "502"
  }
  ["label"]=>
  array(9) {
    [0]=>
    string(8) "charcoal"
    [1]=>
    string(5) "khaki"
    [2]=>
    string(3) "red"
    [3]=>
    string(10) "royal blue"
    [4]=>
    string(1) "s"
    [5]=>
    string(1) "m"
    [6]=>
    string(1) "l"
    [7]=>
    string(2) "xs"
    [8]=>
    string(2) "xl"
  }
  ["default_label"]=>
  array(9) {
    [0]=>
    string(8) "charcoal"
    [1]=>
    string(5) "khaki"
    [2]=>
    string(3) "red"
    [3]=>
    string(10) "royal blue"
    [4]=>
    string(1) "s"
    [5]=>
    string(1) "m"
    [6]=>
    string(1) "l"
    [7]=>
    string(2) "xs"
    [8]=>
    string(2) "xl"
  }
  ["labels"]=>
  array(18) {
    [0]=>
    string(8) "charcoal"
    [1]=>
    string(8) "charcoal"
    [2]=>
    string(5) "khaki"
    [3]=>
    string(5) "khaki"
    [4]=>
    string(3) "red"
    [5]=>
    string(3) "red"
    [6]=>
    string(10) "royal blue"
    [7]=>
    string(10) "royal blue"
    [8]=>
    string(1) "s"
    [9]=>
    string(1) "s"
    [10]=>
    string(1) "m"
    [11]=>
    string(1) "m"
    [12]=>
    string(1) "l"
    [13]=>
    string(1) "l"
    [14]=>
    string(2) "xs"
    [15]=>
    string(2) "xs"
    [16]=>
    string(2) "xl"
    [17]=>
    string(2) "xl"
  }
}

Therefore, Iam not sure the issues you describe @S0FTWEX are related to this fix.
What do I need to reproduce this? And are you sure it does not happen on older php versions?

@splendidinternet
Copy link

We tested this fix and it works successfully without any notices and warnings.

@Flyingmana Flyingmana merged commit f33522f into OpenMage:1.9.4.x Jul 6, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2021

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
6 runs  +4  4 ✔️ +2  2 💤 +2  0 ❌ ±0 

Results for commit f33522f. ± Comparison against base commit 62d9431.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: ConfigurableSwatches Relates to Mage_ConfigurableSwatches PHP 8 Related to PHP8
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants