<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.gettype" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>gettype</refname>
  <refpurpose>Get the type of a variable</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>string</type><methodname>gettype</methodname>
   <methodparam><type>mixed</type><parameter>value</parameter></methodparam>
  </methodsynopsis>
  <para>
   Returns the type of the PHP variable <parameter>value</parameter>. For
   type checking, use <literal>is_*</literal> functions.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>value</parameter></term>
     <listitem>
      <para>
       The variable being type checked.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Possible values for the returned string are:
   <simplelist>
    <member>
      <literal>"boolean"</literal>
     </member>
    <member>
     <literal>"integer"</literal>
    </member>
    <member>
     <literal>"double"</literal> (for historical reasons <literal>"double"</literal> is
     returned in case of a <type>float</type>, and not simply
     <literal>"float"</literal>)
    </member>
    <member>
     <literal>"string"</literal>
    </member>
    <member>
     <literal>"array"</literal>
    </member>
    <member>
     <literal>"object"</literal>
    </member>
    <member>
     <literal>"resource"</literal>
    </member>
    <member>
     <literal>"resource (closed)"</literal> as of PHP 7.2.0
    </member>
    <member>
     <literal>"NULL"</literal>
    </member>
    <member>
     <literal>"unknown type"</literal>
    </member>
   </simplelist>
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>7.2.0</entry>
       <entry>
        Closed resources are now reported as <literal>'resource (closed)'</literal>.
        Previously the returned value for closed resources were <literal>'unknown type'</literal>.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>gettype</function> example</title>
    <programlisting role="php">
<![CDATA[
<?php

$data = array(1, 1., NULL, new stdClass, 'foo');

foreach ($data as $value) {
    echo gettype($value), "\n";
}

?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
integer
double
NULL
object
string
]]>
    </screen>
   </example>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>get_debug_type</function></member>
    <member><function>settype</function></member>
    <member><function>get_class</function></member>
    <member><function>is_array</function></member>
    <member><function>is_bool</function></member>
    <member><function>is_callable</function></member>
    <member><function>is_float</function></member>
    <member><function>is_int</function></member>
    <member><function>is_null</function></member>
    <member><function>is_numeric</function></member>
    <member><function>is_object</function></member>
    <member><function>is_resource</function></member>
    <member><function>is_scalar</function></member>
    <member><function>is_string</function></member>
    <member><function>function_exists</function></member>
    <member><function>method_exists</function></member>
   </simplelist>
  </para>
 </refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
