Type SystemPHP uses a nominal type system with a strong behavioral subtyping relation. The subtyping relation is checked at compile time whereas the verification of types is dynamically checked at run time. PHP's type system supports various atomic types that can be composed together to create more complex types. Some of these types can be written as type declarations. Atomic typesSome atomic types are built-in types which are tightly integrated with the language and cannot be reproduced with user defined types. The list of base types is:
Composite typesIt is possible to combine multiple atomic types into composite types. PHP allows types to be combined in the following ways:
Intersection types
An intersection type accepts values which satisfies multiple
class-type declarations, rather than a single one.
Individual types which form the intersection type are joined by the
Union types
A union type accepts values of multiple different types,
rather than a single one.
Individual types which form the union type are joined by the
Type aliases
PHP supports two type aliases: mixed and
iterable which corresponds to the
union type
of
|