1.2.259. Could Be Null

Mark arguments, properties, class constants and return types that can be null. Null was introduced as a standlone type in PHP 8.2. Before that, null had to be paired with another type.

<?php

// Accept null as input, when used as third argument of file_get_contents
function foo($b) {
    $s = file_get_contents(URL, false, $b);

    // Returns a string
    return shell_exec($s);
}

?>

1.2.259.1. Suggestions

  • Add null typehint to the code (PHP 8.0+).

  • Add ? typehint to the code.

1.2.259.2. Specs

Short name

Typehints/CouldBeNull

Rulesets

All, CE, Typechecks

Exakat since

2.1.2

PHP Version

All

Severity

Major

Time To Fix

Quick (30 mins)

Precision

High

Features

null, typehint, nullable

Available in

Entreprise Edition, Community Edition, Exakat Cloud