<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.types.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'language.types.type-system.php',
    1 => 'Type System',
    2 => 'Type System',
  ),
  'up' => 
  array (
    0 => 'language.types.php',
    1 => 'Tipi di dati',
  ),
  'prev' => 
  array (
    0 => 'language.types.intro.php',
    1 => 'Introduzione',
  ),
  'next' => 
  array (
    0 => 'language.types.null.php',
    1 => 'NULL',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/types/type-system.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.types.type-system" class="sect1">
 <h2 class="title">Type System</h2>

 <p class="para">
  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.
 </p>

 <p class="para">
  PHP&#039;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
  <a href="language.types.declarations.php" class="link">type declarations</a>.
 </p>

 <div class="sect2" id="language.types.type-system.atomic">
  <h3 class="title">Atomic types</h3>
  <p class="para">
   Some atomic types are built-in types which are tightly integrated with the
   language and cannot be reproduced with user defined types.
  </p>

  <p class="para">
   The list of base types is:
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">Built-in types</span>
     <ul class="itemizedlist">
      <li class="listitem">
       <span class="simpara">
        Scalar types:
       </span>
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> type</span>
        </li>
        <li class="listitem">
         <span class="simpara"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> type</span>
        </li>
        <li class="listitem">
         <span class="simpara"><span class="type"><a href="language.types.float.php" class="type float">float</a></span> type</span>
        </li>
        <li class="listitem">
         <span class="simpara"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> type</span>
        </li>
       </ul>
      </li>
      <li class="listitem">
       <span class="simpara"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> type</span>
      </li>
      <li class="listitem">
       <span class="simpara"><span class="type"><a href="language.types.object.php" class="type object">object</a></span> type</span>
      </li>
      <li class="listitem">
       <span class="simpara"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> type</span>
      </li>
      <li class="listitem">
       <span class="simpara"><span class="type"><a href="language.types.never.php" class="type never">never</a></span> type</span>
      </li>
      <li class="listitem">
       <span class="simpara"><span class="type"><span class="type"><a href="language.types.void.php" class="type void">void</a></span></span> type</span>
      </li>
      <li class="listitem">
       <span class="simpara">
        <a href="language.types.relative-class-types.php" class="link">Relative class types</a>:
        <span class="type">self</span>, <span class="type">parent</span>, and <span class="type">static</span>
       </span>
      </li>
      <li class="listitem">
       <span class="simpara">
        <a href="language.types.singleton.php" class="link">Singleton types</a>
       </span>
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara"><span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span>
        </li>
        <li class="listitem">
         <span class="simpara"><span class="type"><a href="language.types.singleton.php" class="type true">true</a></span></span>
        </li>
       </ul>
      </li>
      <li class="listitem">
       <span class="simpara">
        Unit types
       </span>
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara"><span class="type"><a href="language.types.null.php" class="type null">null</a></span></span>
        </li>
       </ul>
      </li>
     </ul>
    </li>
    <li class="listitem">
     <span class="simpara">
      User-defined types (generally referred to as class-types)
     </span>
     <ul class="itemizedlist">
      <li class="listitem">
       <span class="simpara"><a href="language.oop5.interfaces.php" class="link">Interfaces</a></span>
      </li>
      <li class="listitem">
       <span class="simpara"><a href="language.oop5.basic.php#language.oop5.basic.class" class="link">Classes</a></span>
      </li>
      <li class="listitem">
       <span class="simpara"><a href="language.types.enumerations.php" class="link">Enumerations</a></span>
      </li>
     </ul>
    </li>
    <li class="listitem">
     <span class="simpara"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> type</span>
    </li>
   </ul>
  </p>

  <div class="sect3" id="language.types.type-system.atomic.scalar">
   <h4 class="title">Scalar types</h4>
   <p class="simpara">
    A value is considered scalar if it is of type <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>,
    <span class="type"><a href="language.types.float.php" class="type float">float</a></span>, <span class="type"><a href="language.types.string.php" class="type string">string</a></span> or <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>.
   </p>
  </div>

  <div class="sect3" id="language.types.type-system.atomic.user-defined">
   <h4 class="title">User-defined types</h4>
   <p class="simpara">
    It is possible to define custom types with
    <a href="language.oop5.interfaces.php" class="link">interfaces</a>,
    <a href="language.oop5.basic.php#language.oop5.basic.class" class="link">classes</a> and
    <a href="language.types.enumerations.php" class="link">enumerations</a>.
    These are considered as user-defined types, or class-types.
    For example, a class called <code class="literal">Elephant</code> can be defined,
    then objects of type <code class="literal">Elephant</code> can be instantiated,
    and a function can request a parameter of type <code class="literal">Elephant</code>.
   </p>
  </div>
 </div>

 <div class="sect2" id="language.types.type-system.composite">
  <h3 class="title">Composite types</h3>
  <p class="para">
   It is possible to combine multiple atomic types into composite types.
   PHP allows types to be combined in the following ways:
  </p>

  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     Intersection of class-types (interfaces and class names).
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     Union of types.
    </span>
   </li>
  </ul>

  <div class="sect3" id="language.types.type-system.composite.intersection">
   <h4 class="title">Intersection types</h4>
   <p class="para">
    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
    <code class="literal">&amp;</code> symbol. Therefore, an intersection type comprised
    of the types <code class="literal">T</code>, <code class="literal">U</code>, and
    <code class="literal">V</code> will be written as <code class="literal">T&amp;U&amp;V</code>.
   </p>
  </div>

  <div class="sect3" id="language.types.type-system.composite.union">
   <h4 class="title">Union types</h4>
   <p class="para">
    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
    <code class="literal">|</code> symbol. Therefore, a union type comprised
    of the types <code class="literal">T</code>, <code class="literal">U</code>, and
    <code class="literal">V</code> will be written as <code class="literal">T|U|V</code>.
    If one of the types is an intersection type, it needs to be bracketed
    with parenthesis for it to written in <abbr title="Disjunctive Normal Form">DNF</abbr>:
    <code class="literal">T|(X&amp;Y)</code>.
   </p>
  </div>
 </div>

 <div class="sect2" id="language.types.type-system.alias">
  <h3 class="title">Type aliases</h3>

  <p class="para">
   PHP supports two type aliases: <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> and
   <span class="type"><a href="language.types.iterable.php" class="type iterable">iterable</a></span> which corresponds to the
   <a href="language.types.type-system.php#language.types.type-system.composite.union" class="link">union type</a>
   of <code class="literal">object|resource|array|string|float|int|bool|null</code>
   and <code class="literal">Traversable|array</code> respectively.
  </p>

  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    PHP does not support user-defined type aliases.
   </span>
  </p></blockquote>
 </div>

</div><?php manual_footer($setup); ?>