PHP TypeLang Help

Shape Types

Each composite type can be rigidly described by a structural type called a "shape". A shape within the PHP language can be applied to any array or object and contain either implicit or explicit keys.

array{ a: first, b: second }
array{ 1: first, 42: second }
array{ "name-some": first, "escape\nchars": second }
array{ first, second }

Optional Fields

Specifying fields (keys) allows the optionality of the presence of a field. Such fields are indicated by a question mark (?) before the colon (:) symbol: key?: Type.

array{ key?: Type, }
array{ key: Type?, }

Unsealed Shapes

Unsealed (unclosed) shapes mean that the composite type can contain additional fields beyond those described in the shape. Such types must be terminated with the " ... ".

array{ key: type, }
array{ key: type, ... }

Typed Shapes

In addition, such shapes can describe template arguments (types) for values or for keys and values, which are described after the ellipsis (...) char and contain syntax similar to generics.

array{ user: User, ... }
array{ user: User, ...<string, object> }

Attributes

Each shape field allows you to define list of additional attributes. An attribute is additional metadata for a field.

03 February 2025