Really liking the arrow functions in PHP 7.4 so far! Unfortunately already found one missing feature: you can't throw Exceptions from them. The following results in a 'unexpected T_THROW' syntax error:

fn() => throw new Exception('nope');

Would've cleaned up my test, but alas.

5 personen vinden dit leuk

Reacties

Benjamin Coutu
Benjamin Coutu

An expression should have a well-defined return value for propagation. I don‘t think throw qualifies in that sense and should therefore remain a statement, don’t you think?