1.2.1394. Useless Return

The spotted functions or methods have a return statement, but this statement is useless. This is the case for constructor and destructors, whose return value are ignored or inaccessible.

When return is void, and the last element in a function, it is also useless.

<?php

class foo {
    function __construct() {
        // return is not used by PHP
        return 2;
    }
}

function bar(&$a) {
    $a++;
    // The last return, when empty, is useless
    return;
}

?>

1.2.1394.1. Suggestions

  • Remove the return expression. Keep any other calculation.

1.2.1394.2. Specs

Short name

Functions/UselessReturn

Rulesets

All, Analyze

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

Very high

Features

return

Examples

ThinkPHP, Vanilla

Available in

Entreprise Edition, Exakat Cloud