Skip to content

Syntax

Shape keys

A field of a shape has an implicit key or an explicit one. Both kinds may be used together in one shape, the way PHPStan and Psalm allow it: which keys the implicit fields denote is left to whoever reads the shape.

An implicit and an explicit key in one shape.

array{First, name: Second}
type
fields
type
field
key
type

resultTypeLang\Type\NamedTypeNode

An implicit field is a type alone, its position in the shape gives it a numeric index.

array{First, Second, Third}
type
fields
type
type
type

resultTypeLang\Type\NamedTypeNode

An explicit field is a key, a colon (:) and the type: key: Type. The simplest key is an identifier, the same as a type name: it may contain dashes and a namespace, and the words true, false and null are ordinary names here, not literals.

array{a: First, b: Second}
type
fields
field
key
type
field
key
type

resultTypeLang\Type\NamedTypeNode

A dash, a namespace and a reserved word as keys.

array{some-key: First, Some\Name: Second, null: Third}
type
fields
field
key
type
field
key
type
field
key
type

resultTypeLang\Type\NamedTypeNode

A key may be an integer literal in any notation, signed ones included. A float cannot be a key.

array{42: A, -1: B, 0x1F: C}
type
fields
field
literal
type
field
literal
type
field
literal
type

resultTypeLang\Type\NamedTypeNode

A key may be a string literal, which allows characters an identifier does not, escape sequences included.

array{"name some": First, "escape\nchars": Second}
type
fields
field
literal
type
field
literal
type

resultTypeLang\Type\NamedTypeNode

A key may be a class constant.

array{Path\To\ClassName::CONSTANT_NAME: string}
type
fields
field
const
type

resultTypeLang\Type\NamedTypeNode