1.2.694. Mismatched Default Arguments

Arguments are relayed from one method to the other, and the arguments have different default values.

Although it is possible to have different default values, it is worth checking why this is actually the case. This analysis reports the original arguments. Starting from it, follow the usage of the argument in its method, and find calls to other methods.

This analysis omits reporting argument when one of them does not have a default value.

<?php

function foo($a = null, $b = array() ) {
    // foo method calls directly bar.
    // When argument are provided, it's OK
    // When argument are omited, the default value is not the same as the next method
    bar($a, $b);
}

function bar($c = 1, $d = array() ) {

}

?>

1.2.694.1. Suggestions

  • Synchronize default values to avoid surprises

  • Drop some of the default values

1.2.694.2. Specs

Short name

Functions/MismatchedDefaultArguments

Rulesets

All, Analyze, Typechecks

Exakat since

0.12.3

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

typehint, parameter

Examples

SPIP

Available in

Entreprise Edition, Exakat Cloud