<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.var.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.get-debug-type.php',
    1 => 'get_debug_type',
    2 => '変数の型名をデバッグしやすい形で取得する',
  ),
  'up' => 
  array (
    0 => 'ref.var.php',
    1 => '変数操作 関数',
  ),
  'prev' => 
  array (
    0 => 'function.floatval.php',
    1 => 'floatval',
  ),
  'next' => 
  array (
    0 => 'function.get-defined-vars.php',
    1 => 'get_defined_vars',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/var/functions/get-debug-type.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.get-debug-type" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">get_debug_type</h1>
  <p class="verinfo">(PHP 8)</p><p class="refpurpose"><span class="refname">get_debug_type</span> &mdash; <span class="dc-title">変数の型名をデバッグしやすい形で取得する</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.get-debug-type-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>get_debug_type</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   PHP の変数 <code class="parameter">value</code> の、解決済みの名前を返します。
   この関数は、オブジェクトをクラス名に、
   リソースをリソース型の名前に、
   そしてスカラー型の値を型宣言で使われている通常の名前に解決します。
  </p>
  <p class="para">
   <span class="function"><a href="function.gettype.php" class="function">gettype()</a></span> は、歴史的な理由で決まった型の名前を返します。
   この関数は、それよりも実際に使われている型により近い名前を返すという点が異なります。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.get-debug-type-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       型をチェックする変数。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.get-debug-type-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
     返される文字列としてあり得るのは、以下になります:

     <table class="doctable informaltable">
      
       <thead>
        <tr>
         <th>型 + 状態</th>
         <th>戻り値</th>
         <th>備考</th>
        </tr>

       </thead>

       <tbody class="tbody">
        <tr>
         <td>null</td>
         <td>
          <code class="literal">&quot;null&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>boolean (<strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> または <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>)</td>
         <td>
          <code class="literal">&quot;bool&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>整数型</td>
         <td>
          <code class="literal">&quot;int&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>浮動小数点型</td>
         <td>
          <code class="literal">&quot;float&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>文字列</td>
         <td>
          <code class="literal">&quot;string&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>配列</td>
         <td>
          <code class="literal">&quot;array&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>リソース</td>
         <td>
          <code class="literal">&quot;resource (resourcename)&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>リソース(閉じられたもの)</td>
         <td>
          <code class="literal">&quot;resource (closed)&quot;</code>
         </td>
         <td>例: <span class="function"><a href="function.fclose.php" class="function">fclose()</a></span> で閉じられたファイルストリーム</td>
        </tr>

        <tr>
         <td>名前付きのクラスのオブジェクト</td>
         <td>
          名前空間も含めた、クラスの完全修飾名。
          例: <code class="literal">Foo\Bar</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>無名クラスのオブジェクト</td>
         <td>
          <code class="literal">&quot;class@anonymous&quot;</code>。
          クラスが別のクラスを継承したり、
          インターフェイスを実装した場合は、親クラス/親のインターフェイス の名前。
          例: <code class="literal">&quot;Foo\Bar@anonymous&quot;</code>
         </td>
         <td>
          無名クラスのオブジェクトは、<code class="code">$x = new class { ... }</code>  という文法で作成されます。
         </td>
        </tr>

       </tbody>
      
     </table>

  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-function.get-debug-type-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>get_debug_type()</strong></span> の例</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">namespace </span><span style="color: #0000BB">Foo</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">null</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">0.1</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">([]), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'/examples/book.xml'</span><span style="color: #007700">, </span><span style="color: #DD0000">'rb'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(new </span><span style="color: #0000BB">\stdClass</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(new class {}), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />interface </span><span style="color: #0000BB">A </span><span style="color: #007700">{}<br />interface </span><span style="color: #0000BB">B </span><span style="color: #007700">{}<br />class </span><span style="color: #0000BB">C </span><span style="color: #007700">{}<br /><br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(new class implements </span><span style="color: #0000BB">A </span><span style="color: #007700">{}), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(new class implements </span><span style="color: #0000BB">A</span><span style="color: #007700">,</span><span style="color: #0000BB">B </span><span style="color: #007700">{}), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(new class extends </span><span style="color: #0000BB">C </span><span style="color: #007700">{}), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(new class extends </span><span style="color: #0000BB">C </span><span style="color: #007700">implements </span><span style="color: #0000BB">A </span><span style="color: #007700">{}), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>上の例の出力は、
たとえば以下のようになります。</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">null
bool
int
float
string
array
resource (stream)
resource (closed)
stdClass
class@anonymous
Foo\A@anonymous
Foo\A@anonymous
Foo\C@anonymous
Foo\C@anonymous</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.get-debug-type-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.gettype.php" class="function" rel="rdfs-seeAlso">gettype()</a> - 変数の型を取得する</span></li>
    <li><span class="function"><a href="function.get-class.php" class="function" rel="rdfs-seeAlso">get_class()</a> - オブジェクトのクラス名を返す</span></li>
   </ul>
  </p>
 </div>

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