4.2.42. Set Null Type

Adds a Null type to typehints when necessary.

This cobbler only adds a null type when there is already another type. It doesn’t add a null type when no type is set.

It works on methods, functions, closures and arrow functions. It doesn’t work on properties.

The null type is added as a question mark ? when the type is unique, and as null when the types are multiple.

4.2.42.1. Before

<?php

function foo() : int {
    if (rand(0, 1)) {
        return 1;
    } else {
        return null;
    }
}

?>

4.2.42.2. After

<?php

function foo() : ?int {
    if (rand(0, 1)) {
        return 1;
    } else {
        return null;
    }
}

?>

4.2.42.3. Reverse Cobbler

4.2.42.4. Specs

Short Name

Functions/SetNullType

Exakat version

2.3.0

Available in

Entreprise Edition, Exakat Cloud