1.2.572. Infinite Recursion

A method is calling itself, with unchanged arguments. This might repeat indefinitely.

This rules applies to recursive functions without any condition. This also applies to function which inject the incoming arguments, without modifications.

<?php

function foo($a, $b) {
    if ($a > 10) {
        return;
    }
    foo($a, $b);
}

function foo2($a, $b) {
    ++$a;   // $a is modified
    if ($a > 10) {
        return;
    }
    foo2($a, $b);
}

?>

1.2.572.1. Suggestions

  • Modify arguments before injecting them again in the same method

  • Use different values when calling the same method

1.2.572.2. Specs

Short name

Structures/InfiniteRecursion

Rulesets

All, Analyze

Exakat since

1.8.6

PHP Version

All

Severity

Major

Time To Fix

Quick (30 mins)

Precision

Very high

Features

loop, recursion, infinite

Available in

Entreprise Edition, Exakat Cloud