This RFC is still in progress
A common pattern in PHP is iterating through a list of objects and executing certain methods of the objects. This is especially common when it comes to 1:n-relations (e.g. one object, n adapters). This proposal is meant to abstract those iterations in convenient functional constructs by adding method call iterators and iterator functions.
foreach ($list as $element) { $element->method(); }
$result = array(); foreach ($list as $element) { $result[] = $element->method(); }
foreach ($list as $element) { if ($element->conditionalMethod()) { $element->method(); } }
$result = array(); foreach ($list as $element) { if ($element->conditionalMethod()) { $result[] = $element->method(); } }
Extracting the required functionality to leads to the following required additions:
iterate(new CallIterator($list, 'method'));
$result = iterate(new CallIterator($list, 'method'), true);