2 ms·
> For a single statement this can be extremely clear PHP arrow functions can only contain a single statement and always implicitly return, so that sort of thin
by deergomoo 7y ago
> For a single statement this can be extremely clear
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).
- johannes1234321 7y agoUsing $this was just a simple example where all three cases could easily do the same. Make it $bar :) Anyways: People are capable of writing loooooong expressions (chaining with && can be good to handle errors from multiple operations in one place (till you have to figure out which specific condition broke)) Thus "single expression" isn't neccisarily short ;) Anyways: Point is "it can be useful, but developers should think, what they are doing" Perl's "there's more than one way to do it" probably goes too far, but being able to focus on the relevant parts and being able to providing the amount of context needed are good things.