PHP TypeLang Help

Callable Types

Callable types describe an arbitrary type that describes a function.

Each callable MAY have a list of parameters and/or a return type definition.

Named Parameters

The name after the type of the parameter defines the parameter that allows passing by name.

The name must appear after the parameter type and begin with a " $ " sign. Just like in the PHP language.

Output Parameters

Passing a parameter by reference means that the function can change the passed variable while it is running.

To indicate that a parameter is passed by reference, an " & " sign is used after the type and before the name.

Optional Parameters

An optional parameter means that the argument may not be passed when such a function is called.

An optional parameter is indicated by the " = " sign at the end of the parameter description.

Variadic Parameters

Variadic parameters are indicated by the " ... " placed after the type. Where a parameter carries both markers, the ampersand (" & ") comes first.

Template Parameters

A callable MAY declare the template parameters it introduces, written as a <...> list between the name and the parameter list. Each parameter is a name, optionally followed by the bounds put on it.

A parameter accepts three kinds of limit, each written at most once. The two bounds are written in either order, and the default is written last: a bound behind it would read as a bound of the default itself.

  • of T or as T — the upper bound: the argument is to be a subtype of T. The two words mean the same and are kept as they are written.

  • super T — the lower bound: the argument is to be a supertype of T.

  • = T — the default: the type the parameter takes when no argument is passed. It bounds nothing.

The words are not case-sensitive, so an OF reads the same way an of does.

12 September 2026