-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 Framework\Data\Collection::each() method #7330
Conversation
foreach ($args->_items as $k => $item) { | ||
$args->_items[$k] = call_user_func($objMethod, $item); | ||
foreach ($this->getItems() as $item) { | ||
call_user_func_array([$item, $objMethod], $args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call_user_func_array
is quite slow compared to argument unpacking[1].
This should probably be changed to:
$item->$objMethod(...$args);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, updated the PR.
Additional enhancement: in order to avoid surprising behavior allow passing a |
Unfortunately I can't make the tests pass because:
To fix the integration tests they just need to be rerun at a different time when the service happens to be up and running, and to fix the static test the PSR2 code sniffer rule needs to be fixed. |
@Vinai thank you for your contribution to Magento 2 project |
The method
\Magento\Framework\Data\Collection::each()
sadly is completely broken, as it iterates over$args->_items
instead of the collection items.This PR add test coverage and fixes the method.