1.2.20. Add Return Typehint

Add returntype to methods, functions, closures and arrow functions. The return types are read from the code and deduced, based on literal values, local types and operations.

<?php

// This has no type, but could use int
function foo() {
    return 1;
}

// This has no type, but could use string
function goo(string $a) {
    return $a;
}

// This has no type, but could use string
function hoo($a) {
    return $a - 2;
}

?>

1.2.20.1. Specs

Short name

Complete/ReturnTypehint

Rulesets

All, Changed Behavior, First, NoDoc

Exakat since

2.3.9

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud