Nullable Return Types Beginning in PHP 7.1

By preceding the type declaration with a question mark (?), PHP allows returning a null or void value:

function get_thing($thing): ?string {
    if ( ! empty($thing)) {
        return $thing;
    } else {
        return null;
    }
}

Tags

 PHP  PHP 7.1  type safety