1.2.1065. Semantic Typing

Arguments names are only useful inside the method’s body. They are not actual type.

<?php

// arguments should be a string and an array
function foo($array, $str) {
    // more code
    return $boolean;
}

// typehint is actually checking the values
function bar(iterable $closure) : bool {
    // more code
    return true;
}

?>

1.2.1065.1. Suggestions

  • Use a typehint to make sure the argument is of the expected type.

1.2.1065.2. Specs

Short name

Functions/SemanticTyping

Rulesets

All, Semantics

Exakat since

2.0.5

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

typehint

Available in

Entreprise Edition, Exakat Cloud