-
-
Notifications
You must be signed in to change notification settings - Fork 209
Description
The documentation for invoke_first and invoke_last says, in that order:
mixed Functional\invoke_first(array|Traversable $collection, string $methodName[, array $methodArguments])Invokes method$methodNameon the first object in the$collectionand returns the results of the call
and
mixed Functional\invoke_last(array|Traversable $collection, string $methodName[, array $methodArguments])Invokes method$methodNameon the last object in the$collectionand returns the results of the call
However, the implementation of these functions seems to say otherwise. Take invoke_first as an example:
function invoke_first($collection, $methodName, array $arguments = [])
{
//... uninteresting assertions
foreach ($collection as $element) {
$callback = [$element, $methodName];
if (is_callable($callback)) {
return $callback(...$arguments);
}
}
return null;
}This means we're calling $methodName on the first applicable object in the collection. Which means, for example, we have ['foo', 'bar', $objectWithMethodName], then $objectWithMethodName->$methodName() will be called instead of 'foo'->$methodName(), and the result of $objectWithMethodName->$methodName() will be returned instead of NULL.