PHP 8 · Types and functions

Use union types

Accept more than one type for a parameter.

function id(int|string $value): int|string
{
    return $value;
}

Official PHP 8 documentation

More types and functions commands

All types and functions commands · PHP 8 cheatsheet

Was this page helpful?