Skip to content

Latest commit

 

History

History
74 lines (52 loc) · 3.24 KB

atomic_types.md

File metadata and controls

74 lines (52 loc) · 3.24 KB

Atomic types

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:

Magical types

Top types, bottom types and empty

mixed

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.

never

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.

empty

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.

Other

  • 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.