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 $methodName on the first object in the $collection and returns the results of the call
and
mixed Functional\invoke_last(array|Traversable $collection, string $methodName[, array $methodArguments]) Invokes method $methodName on the last object in the $collection and 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.
The documentation for
invoke_firstandinvoke_lastsays, in that order:and
However, the implementation of these functions seems to say otherwise. Take
invoke_firstas an example:This means we're calling
$methodNameon 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 ofNULL.