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 reportMixedIssues
flag is turned on, or when you're on level 1.
It can be aliased to no-return
or never-return
in docblocks. Note: it replaced the old empty
type that used to exist in Psalm
This is the bottom type in PHP's type system. It's used to describe a type that has no possible value. It can happen in multiple cases:
- the actual
never
type from PHP 8.1 (can be used in docblocks for older versions). This type can be used as a return type for functions that will never return, either because they always throw exceptions or always exit() - an union type that have been stripped for all its possible types. (For example, if a variable is
string|int
and we perform a is_bool() check in a condition, the type of the variable in the condition will benever
as the condition will never be entered) - it can represent a placeholder for types yet to come — a good example is the type of the empty array
[]
, which Psalm types asarray<never, never>
, the content of the array is void so it can accept any content - it can also happen in the same context as the line above for templates that have yet to be defined
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.