1.2.330. Declare strict_types Usage¶
Usage of strict_types
. By default, PHP attempts to change the original type to match the type specified by the type-declaration. With an explicit strict_types
declaration, PHP ensures that the incoming argument has the exact type.
strict_types
were introduced in PHP 7.0.
<?php
// Setting strict_types;
declare(strict_types = 1);
function foo(int $i) {
echo $i;
}
// Always valid : displays 1
foo(1);
// with strict types, this emits an error
// without strict types, this displays 1
foo(1.7);
?>
See also declare.
1.2.330.1. Connex PHP features¶
1.2.330.1.1. Specs¶
Short name |
Php/DeclareStrictType |
Rulesets |
|
Exakat since |
0.12.1 |
PHP Version |
With PHP 7.0 and more recent |
Severity |
|
Time To Fix |
|
Precision |
Very high |
Available in |