%s%s%s(): Return value must be of type %s, %s returned

Description

This error appears when calling a method with a return value, but without an explicit return statement. This means that when the method reachs its end, eventually, it will end without a returned value. Yet, the method signature declares that it will return a specific type.

A different error message is returned when an empty return statement is used.

Example

<?php

function foo() : int {}

?>

Literal Examples

  • foo(): Return value must be of type int, none returned

Solutions

  • Add a return call, with a valid value.

  • Remove the return type.

  • Add a null to the return type, and return it (void is not possible with another type).