1.2.862. 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.862.2. Connex PHP features¶
1.2.862.2.1. Suggestions¶
Do not use
int
as a class name, an interface name or a trait name.
1.2.862.2.2. Specs¶
Short name |
Php/NotScalarType |
Rulesets |
|
Exakat since |
1.0.7 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Available in |