Skip to content

Syntax

Names

A type name is written the way PHP writes an identifier, with one difference: a dash (-) may stand inside a name.

  • The first character is a letter or an underscore (_).
  • The rest are letters, digits, underscores and dashes, a dash cannot be the last character.
  • A letter is a-z, A-Z or a byte from 0x80 to 0xff.
  • A dash is allowed only in a name without a namespace: non-empty-string is a name, Some\non-empty-string and non-empty\Some are not.

The words true, false and null in any case are literals, not names, when they stand alone.

ExampleTypeName
type

resultTypeLang\Type\NamedTypeNode

A dash inside a name.

example-type
type

resultTypeLang\Type\NamedTypeNode

A reserved word as a part of a name.

true-type
type

resultTypeLang\Type\NamedTypeNode

A name may carry a namespace, separated with a backslash (\) the way PHP does it. A backslash may stand inside a name or at its start, not at its end. With a namespace, the reserved words are ordinary names.

A relative name.

Example\Name
type

resultTypeLang\Type\NamedTypeNode

A fully qualified name.

\Absolute\Type\Name
type

resultTypeLang\Type\NamedTypeNode

The reserved words as a namespace and a name, not literals.

true\null
type

resultTypeLang\Type\NamedTypeNode

The $this variable denotes the type of the object the type is written on. It is a type of its own, so it stands wherever a type stands: inside a union, behind a question mark, or as the type a callable returns.

The type of the current object.

$this
$this

resultTypeLang\Type\ThisTypeNode

The current object type, or nothing at all.

?$this
nullable
$this

resultTypeLang\Type\WrappingTypeNode\NullableTypeNode

A callable returning the object it was called on.

callable(): $this
callable
params
$this

resultTypeLang\Type\Callable\CallableTypeNode