This item I didn't pay that much attention to first time around:
- any callable can be turned into a Closure object (okay, you could already do that with
Closure::fromCallable
but now there's specific syntax for it)
That goes for any callable, including plain strings and arrays that are supposed to be the names of functions.
array_map('somefn', $array)
can be written
array_map(somefn(...), $array)
and
array_map([$object, 'method'], $array)
becomes the much more intuitive-looking
array_map($object->method(...), $array)
And they're still first-class values:
$mapping = $object->method(...);
$mapped = array_map($mapping, $array);
That last point makes them even better than string or array callables. Which function gets used when a callable is used depends on what is in scope at that moment; which methods are visible, which namespaces are in use, and so on. While most callbacks get created and used almost immediately, it's perfectly reasonable to want to pass them around to other functions, and entirely possible to create a callback that isn't actually callable at all because there is no function anywhere with a matching name: it won't be checked until you try to actually use it.
All of those might be different from when the callable was defined, and the one that's picked may not be the one that was intended (there may not even be a suitable candidate available).
Creating a first-class Closure object instead means that the name is bound to the relevant function at the time the object is created: much more consistent, and you're told sooner if there is a problem with the name you're trying to use.