<?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 => 'zh',
  ),
  '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' => 'zh',
    '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

(PHP 4, PHP 5, PHP 7)
strlen -- Get string length

说明
strlen ( string $string ) : int

返回给定的字符串 string 的长度。
</pre></div>
     </div>
    </p>
    <p class="para">
     <table class="doctable table">
      <caption><strong>对函数定义的解释</strong></caption>
      
       <thead>
        <tr>
         <th>组成部分</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>
          第一个（本例中是唯一的）参数，在该函数中名为 <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>
          该函数返回的值的类型，这里为整型 <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>（即以数字来衡量的字符串的长度）。
         </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">
     这是什么意思？<span class="function"><a href="function.in-array.php" class="function">in_array()</a></span>
     返回一个“<a href="language.types.boolean.php" class="link">布尔</a>”值，成功（如果在参数
     <code class="parameter">haystack</code> 中能找到参数
     <code class="parameter">needle</code>）则返回 <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>（如果在参数 <code class="parameter">haystack</code> 中找不到参数
     <code class="parameter">needle</code>）。第一个参数被命名为
     <code class="parameter">needle</code> 且其<a href="language.types.php" class="link">类型</a>不定，因此我们将其称为“<em>混和</em>”类型。该混和类型的
     <code class="parameter">needle</code> 参数（我们要找的对象）可以是一个标量的值（字符串、整数、或者<a href="language.types.float.php" class="link">浮点数</a>），或者一个<a href="language.types.array.php" class="link">数组</a>。<code class="parameter">haystack</code>（我们寻找的范围）是第二个参数。第三个<em>可选</em>参数被命名为
     <code class="parameter">strict</code>。所有的可选参数都用
     <em>[</em> 方括号 <em>]</em> 括起来。手册表明
     <code class="parameter">strict</code> 参数默认值为布尔值
     <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
      [, int $flags = 0 [, int $offset = 0 ]]] ) : int
</pre></div>
     </div>
    </p>
    <p class="para">
     在这个例子中，我们可以看到，第三个可选参数 <code class="parameter">&amp;$matches</code> 会意引用方式传递。
    </p>
    <p class="para">
     有的函数包含更复杂的 PHP 版本信息。我们拿
     <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">
<div class="cdata"><pre>
(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7)
</pre></div>
     </div>
    </p>
    <p class="para">
     它意味着该函数只可在 PHP 4.3.0 及以后发布的版本中使用。
    </p>
   </div><?php manual_footer($setup); ?>