1.2.1425. Weak Typing

The variable’s validation is not enough to allow for a sophisticated usage. For example, the variable is checked for null, then used as an object or an array.

<?php

if ($a !== null) {
    echo $a->b;
}

?>

See also From assumptions to assertions.

1.2.1425.1. Suggestions

  • Use instanceof when checking for objects

  • Use is_array() when checking for arrays. Also consider is_string(), is_int(), etc.

  • Use typehint when the variable is an argument

1.2.1425.2. Specs

Short name

Classes/WeakType

Rulesets

All, Analyze, Changed Behavior

Exakat since

1.2.8

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

Very high

Features

typehint

Examples

TeamPass

Available in

Entreprise Edition, Exakat Cloud