PHP 8 · Types and functions

Declare types

Type parameters and return values. ?string means string or null.

function greet(string $name, ?string $title = null): string
{
    return trim("$title $name");
}

Official PHP 8 documentation

More types and functions commands

All types and functions commands · PHP 8 cheatsheet

Was this page helpful?