1.2.1424. Weak Type With Array

Using array as a type, to use specific index later.

The type of array is too weak : it allows to know that the array syntax has to be used in the function. Yet, it doesn’t enforce the presence or absence of a specific index.

<?php

function foo(array $variable) {
     echo $array['display'];
}

?>

See also Stop using Arrays and Never* Use Arrays.

1.2.1424.1. Suggestions

  • Use a class as type, instead of

1.2.1424.2. Specs

Short name

Arrays/WeakType

Rulesets

All, Analyze, Changed Behavior

Exakat since

2.5.1

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

array

Available in

Entreprise Edition, Exakat Cloud