Atomic types are the basic building block of all type information used in Psalm. Multiple atomic types can be combined, either with union types or intersection types. Psalm allows many different sorts of atomic types to be expressed in docblock syntax:
- int
- positive-int
- float
- string
- class-string and class-string<Foo>
- trait-string
- enum-string
- callable-string
- numeric-string
- literal-string
- bool
- array-key
- numeric
- scalar
- array & non-empty-array
- array<int, string>
- string[]
- list & non-empty-list
- list<string>
- array{foo: int, bar: string}
- callable-array
- (T is true ? string : bool)
key-of<Foo\Bar::ARRAY_CONST>
value-of<Foo\Bar::ARRAY_CONST>
T[K]
This is the top type in PHP's type system, and represents a lack of type information. Psalm warns about mixed
types when the totallyTyped
flag is turned on, or when you're on level 1.
This is the bottom type in PHP's type system, and usually represents a return type for a function that can never actually return, such as die()
, exit()
, or a function that always throws an exception. It may also be written in docblocks as no-return
or never-return
.
A type that's equivalent to a "coming soon" sign. Psalm uses this type when it’s awaiting more information — a good example is the type of the empty array []
, which Psalm types as array<empty, empty>
. Psalm treats empty
in a somewhat similar fashion to never
when combining types together — empty|int
becomes int
, just as never|string
becomes string
.
iterable
- represents the iterable pseudo-type. Like arrays, iterables can have type parameters e.g.iterable<string, Foo>
.void
- can be used in a return type when a function does not return a value.resource
represents a PHP resource.