<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/about.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'about.prototypes.php',
    1 => '関数の定義(プロトタイプ)を読むには',
    2 => '関数の定義(プロトタイプ)を読むには',
  ),
  'up' => 
  array (
    0 => 'about.php',
    1 => 'マニュアルについて',
  ),
  'prev' => 
  array (
    0 => 'about.notes.php',
    1 => 'ユーザーノートについて',
  ),
  'next' => 
  array (
    0 => 'about.phpversions.php',
    1 => '本マニュアルに記載された PHP のバージョン',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'appendices/about.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="about.prototypes" class="sect1">
    <h2 class="title">関数の定義(プロトタイプ)を読むには</h2>
    <p class="para">
     各関数についてクイックリファレンスが記述されているので、
     マニュアルを読み理解するノウハウは PHP の利用をより簡単にしてくれます。
     例示やカットアンドペーストに頼るより、関数の定義（プロトタイプ）を
     読む方法を覚えるべきです。やってみましょう:
    </p>
    <blockquote class="note"><p><strong class="note">注意</strong>: 
     <strong>
      前提条件: <a href="language.types.php" class="link">型</a>の基本的な理解
     </strong><br />
     <p class="para">
      PHP は型についてルーズな言語ですが、重要な意味があるので、
      <a href="language.types.php" class="link">型</a>の基本を理解することは重要です。
     </p>
    </p></blockquote>
    <p class="para">
     関数の定義には<a href="functions.returning-values.php" class="link">戻り値</a>が
     どんな型であるかが示されています。最初の例として、
     <span class="function"><a href="function.strlen.php" class="function">strlen()</a></span>の定義を考えてみましょう。
    </p>
    <p class="para">
    <div class="example-contents screen">
<div class="cdata"><pre>
strlen ( string $string ) : int
 
(PHP 4, PHP 5, PHP 7)
 strlen -- 文字列の長さを得る
 
 説明
int strlen ( string $string )
 
指定した文字列の長さを返します
</pre></div>
     </div>
    </p>
    <p class="para">
     <table class="doctable table">
      <caption><strong>関数の定義の説明</strong></caption>
       
        <thead>
         <tr>
          <th>Part</th>
          <th>説明</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>
           strlen
          </td>
          <td>
           関数の名前
          </td>
         </tr>

       <tr>
        <td>
          (PHP 4, PHP 5, PHP 7)
        </td>
        <td>
         strlen()は PHP 4 と PHP 5、そして PHP 7 のすべてのバージョンで使用できる
        </td>
       </tr>

       <tr>
        <td>
          ( string $string )
        </td>
        <td>
         strlen() 関数の最初の（この場合は唯一の）引数が
         <code class="parameter">string</code>という名前であり
         それは文字列(<span class="type"><a href="language.types.string.php" class="type string">string</a></span>)である
        </td>
       </tr>

       <tr>
        <td>
         int
        </td>
        <td>
         関数が戻す値の型。ここでは整数型
         (文字列の長さが数字で数えられている)
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
   <p class="para">
    上の関数定義は、一般的な書き方では以下のようにも書けます。
   </p>
   <p class="para">
    <div class="example-contents screen">
<div class="cdata"><pre>
     function name    ( parameter type   parameter name ) : returned type
</pre></div>
    </div>
   </p>
   <p class="para">
    多くの関数は複数の引数を取ります。例えば <span class="function"><a href="function.in-array.php" class="function">in_array()</a></span>。
    このプロトタイプは次のようになります:
   </p>
   <p class="para">
    <div class="example-contents screen">    
<div class="cdata"><pre>
      in_array ( mixed $needle, array $haystack , bool $strict = false ) : bool
</pre></div>
    </div>
   </p>
   <p class="para">
    これは何を意味しているのでしょう？ in_array() は
    <a href="language.types.boolean.php" class="link">boolean</a> の値を返します。
    成功した場合は <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>(<code class="parameter">needle</code> が
      <code class="parameter">haystack</code> の中にある場合)、失敗した場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します
      (<code class="parameter">needle</code> が <code class="parameter">haystack</code>
      の中にない場合)。最初の引数は <code class="parameter">needle</code>
      と名づけられており、それは多くの違った<a href="language.types.php" class="link">
      型</a>をとることができます。その場合&quot;<em>mixed</em>&quot;と
      呼ばれます。
      <code class="parameter">needle</code> (我々が探しているもの)はスカラー値（文字列,整数,
      又は <a href="language.types.float.php" class="link">float</a>)でも、
      <a href="language.types.array.php" class="link">配列</a>でもかまいません。
      <code class="parameter">haystack</code> (対象を探す配列)は二番目の引数です。
      三番目の<em>オプション</em>の引数は <code class="parameter">strict</code>
      と名づけられています。全てのオプション引数はデフォルト値を持ちます。
      デフォルト値が不明な場合、<code class="literal">?</code> と表示されます。
      <code class="parameter">strict</code> パラメータはデフォルトでは boolean の
      <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> であるとマニュアルに述べられています。機能の詳細については
      各関数のマニュアルをご覧ください。
   </p>
    <p class="para"> 
     さらに、&amp; (アンパサンド) 記号を関数のパラメータの前につけると、
     そのパラメータを<a href="language.references.pass.php" class="link">リファレンス渡し</a>にすることができます。
    </p>
    <p class="para">
     <div class="example-contents screen"> 
<div class="cdata"><pre>
       preg_match ( string $pattern , string $subject , array &amp;$matches = null,
       int $flags = 0 , int $offset = 0 ) : int|false
</pre></div>
     </div>
    </p>
    <p class="para">
     この例では、三番目のオプションのパラメータ <code class="parameter">&amp;$matches</code>
     がリファレンス渡しとなります。
    </p>
   <p class="para">
    より複雑なバージョンとの関係を有する関数もあります。以下が
    <span class="function"><a href="function.html-entity-decode.php" class="function">html_entity_decode()</a></span> の例です。
   </p>
   <p class="para">
    <div class="example-contents screen">    <br />
     (PHP 4 &gt;= 4.3.0, PHP 5, PHP 7)<br />
    </div>
   </p>
   <p class="para">
    これは、この関数が
    PHP 4.3.0 以降のバージョンでのみ利用可能であることを意味します。
   </p>
  </div><?php manual_footer($setup); ?>