The Never Function Arrow

../_images/neverFunctionArrow.png

This is a rare occurrence: that syntax is not valid in PHP 8.1, but valid before and after.

In PHP 7.4 and 8.0, the syntax is valid, because never was not a reserved type. PHP considered it as a class name, but since die would prevent any return, it is not actually used.

Starting PHP 8.2, PHP recognizes the absence of return, due to the die, and accepts it.

Also, great edge case of a closure with a (implicit) return, but typed never. Actually, it doesn’t work with a regular return.

See Also

PHP Error Messages

PHP Features