%s(): never-returning function must not implicitly return

Description

A function with the never return type must return anything. This means no return keyword, but also, no possibility to reach the end of the method, as it would trigger automatically a return null;.

Example

<?php

function foo(): never {
    if (true) {
        throw new Exception('bad');
    }
}

foo();
?>

Literal Examples

  • foo(): never-returning function must not implicitly return

Solutions

  • Add a die at the end of the method.

  • Add a throw at the end of the method.

In more recent PHP versions, this error message is now %s(): never-returning %s must not implicitly return.