|
|
|
|
|
by johannes1234321
2398 days ago
|
|
This is a matter of the situation. For a single statement this can be extremely clear, if the function becomes longer being explicit is nice. And at some length the thing should have a name. usort($data, fn($l, $r) => $this->foo($l, $r));
vs. usort($data, function($l, $r) use ($this) { return $this->foo($l, $r); });
vs. usort($data, [$this, 'foo']);
|
|
PHP arrow functions can only contain a single statement and always implicitly return, so that sort of thing is exactly what they're designed for.
Although worth noting with your second example that you haven't needed to capture $this in closures since 5.4, and in fact it is an error to do so now (though I'm not sure when that was introduced).