Tag Archives: PHP 8.1

PHP 8.1: `never` Return Type is Dangerous

There are many features already introduced in PHP 8.1, and among them the new never return type:

function doSomething(): never {
    // do something
    die();
}

The idea is pretty straightforward: if the execution flow is never supposed to leave the function, it should be marked as never. If the execution flow somehow reaches the end of the function, PHP will throw an error.

Although it seems to me like a good idea, there’s a hidden catch we need to be cautious about.

Continue reading »