1.2.288. Could Typehint

Arguments that are tested with instanceof, is_array(), is_string(), etc. could be modernized with a typehint.

<?php

function foo($a, $b) {
    // $a is tested for B with instanceof.
    if (!$a instanceof B) {
        return;
    }

    // More code
}

function foo(B $a, $b) {
    // May omit the initial test

    // More code
}

?>

1.2.288.1. Suggestions

  • Add the typehint, remove the test on the type

1.2.288.2. Specs

Short name

Functions/CouldTypehint

Rulesets

All, Changed Behavior

Exakat since

0.11.5

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

typehint

Available in

Entreprise Edition, Exakat Cloud