1.2.855. Not A Scalar Type

int is the actual PHP scalar type, not integer.

PHP 7 introduced several scalar types, in particular int, bool, string and float. Those three types are easily mistaken with integer, boolean, real and double.

Unless those classes actually exists, PHP emits some strange error messages. Thanks to Benoit Viguier for the original idea for this analysis.

<?php

// This expects a scalar of type 'integer'
function foo(int $i) {}

// This expects a object of class 'integer'
function abr(integer $i) {}

?>

See also Type declarations and PHP RFC: Scalar Type Hints.

1.2.855.1. Suggestions

  • Do not use int as a class name, an interface name or a trait name.

1.2.855.2. Specs

Short name

Php/NotScalarType

Rulesets

All, Changed Behavior, PHP recommendations, Typechecks

Exakat since

1.0.7

PHP Version

All

Severity

Major

Time To Fix

Instant (5 mins)

Precision

Very high

Features

scalar-typehint

Available in

Entreprise Edition, Exakat Cloud