Rechercher une fonction PHP

Type System

PHP 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 types

Some 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:

PHP: Type System - Manual Home of Manuel PHP  Contents Haut

Composite types

It is possible to combine multiple atomic types into composite types. PHP allows types to be combined in the following ways:

  • Intersection of class-types (interfaces and class names).
  • Union of types.

PHP: Type System - Manual Home of Manuel PHP  Contents Haut

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 & symbol. Therefore, an intersection type comprised of the types T, U, and V will be written as T&U&V.

PHP: Type System - Manual Home of Manuel PHP  Contents Haut

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 | symbol. Therefore, a union type comprised of the types T, U, and V will be written as T|U|V. If one of the types is an intersection type, it needs to be bracketed with parenthesis for it to written in DNF: T|(X&Y).

PHP: Type System - Manual Home of Manuel PHP  Contents Haut

Type aliases

PHP supports two type aliases: mixed and iterable which corresponds to the union type of object|resource|array|string|float|int|bool|null and Traversable|array respectively.

Note: PHP does not support user-defined type aliases.

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-language.types.type-system.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut