Never Arrow Function¶
The never type requires the closure to not return, but the arrow function always returns something. By using die(), that closure doesn’t return anymore, but PHP only recognized this since PHP 8.2. Before PHP 8.1, it was valid syntax, as never was recognized as a class name.
PHP code¶
<?php
fn($a) : never => die();
?>
Before¶
PHP Fatal error: A never-returning function must not return
Fatal error: A never-returning function must not return
After¶
PHP version change¶
This behavior changed in 8.1