Movatterモバイル変換


[0]ホーム

URL:


PHP 8.5.0 Alpha 2 available for testing
    NULL »
    « Introduction

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

    Scalar types

    A value is considered scalar if it is of typeint,float,string orbool.

    User-defined types

    It is possible to define custom types withinterfaces,classes andenumerations. These are considered as user-defined types, or class-types. For example, a class calledElephant can be defined, then objects of typeElephant can be instantiated, and a function can request a parameter of typeElephant.

    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.

    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 typesT,U, andV will be written asT&U&V.

    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 typesT,U, andV will be written asT|U|V. If one of the types is an intersection type, it needs to be bracketed with parenthesis for it to written inDNF:T|(X&Y).

    Type aliases

    PHP supports two type aliases:mixed anditerable which corresponds to theunion type ofobject|resource|array|string|float|int|bool|null andTraversable|array respectively.

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

    Found A Problem?

    Learn How To Improve This PageSubmit a Pull RequestReport a Bug
    add a note

    User Contributed Notes

    There are no user contributed notes for this page.
    To Top
    and to navigate •Enter to select •Esc to close
    PressEnter without selection to search using Google

    [8]ページ先頭

    ©2009-2025 Movatter.jp