1.2.1342. Use Nullable Type¶
The code uses nullable type, available since PHP 7.1.
Nullable Types are an option to type hint : they allow the passing value to be null, or another type.
According to the authors of the feature : ‘It is common in many programming languages including PHP to allow a variable to be of some type or null. This null often indicates an error or lack of something to return.’
<?php
function foo(?string $a = 'abc') : ?string {
return $a.b;
}
?>
See also Type declarations and PHP RFC: Nullable Types.
1.2.1342.1. Connex PHP features¶
1.2.1342.1.1. Specs¶
Short name |
Php/UseNullableType |
Rulesets |
All, Appinfo, CE, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70 |
Exakat since |
0.8.4 |
PHP Version |
With PHP 7.1 and more recent |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |