1.2.1383. Useless Default Argument

One of the argument has a default value, and this default value is never used. Every time the method is called, the argument is provided explicitly, rendering the default value actually useless.

<?php

function goo($a, $b = 3) {
    // do something here
}

// foo is called 3 times, and sometimes, $b is not provided.
goo(1,2);
goo(1,2);
goo(1);


function foo($a, $b = 3) {
    // do something here
}

// foo is called 3 times, and $b is always provided.
foo(1,2);
foo(1,2);
foo(1,2);
?>

1.2.1383.1. Suggestions

  • Remove the default value

  • Remove the explicit argument in the function call, when it is equal to the default value

1.2.1383.2. Specs

Short name

Functions/UselessDefault

Rulesets

All, Changed Behavior, Suggestions

Exakat since

1.7.9

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

function, default

Available in

Entreprise Edition, Exakat Cloud