Skip to content

Instantly share code, notes, and snippets.

@navarr
Created May 26, 2016 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navarr/416aa8df188af274956f22bd47be861b to your computer and use it in GitHub Desktop.
Save navarr/416aa8df188af274956f22bd47be861b to your computer and use it in GitHub Desktop.
<?php
array_walk($attributes, function($definition, $attribute) use ($defaults, $catalog) {
$definition = array_merge($defaults, $definition);
$catalog->addAttribute('catalog_product', $attribute, $definition);
});
foreach($attributes as $definition => $attribute) {
$definition = array_merge($defaults, $definition);
$catalog->addAttribute('catalog_product', $attribute, $definition);
}
@navarr
Copy link
Author

navarr commented May 26, 2016

Which one of these is "better"?

"Refactoring to Collections" would suggest that it's array_walk. Perhaps because array_walk specifically defines what it uses, it's better? $defaults and $catalog could, if so desired, be refactored out into a third parameter of array_walk and the closure that would be an object type that would specifically define what those are.

Where as foreach does not have that option.

But is that really better?

And does it matter that this is an Install Script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment