<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'about.prototypes.php',
    1 => 'How to read a function definition (prototype)',
    2 => 'How to read a function definition (prototype)',
  ),
  'up' => 
  array (
    0 => 'about.php',
    1 => 'About the manual',
  ),
  'prev' => 
  array (
    0 => 'about.notes.php',
    1 => 'About user notes',
  ),
  'next' => 
  array (
    0 => 'about.phpversions.php',
    1 => 'PHP versions documented in this manual',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    '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">How to read a function definition (prototype)</h2>
   <p class="para">
    Each function in the manual is documented for quick reference. Knowing how 
    to read and understand the text will make learning PHP 
    much easier.  Rather than relying on examples or cut/paste, everyone should 
    know how to read function definitions (prototypes).  Let&#039;s begin:
   </p>
   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <strong>
     Prerequisite: Basic understanding of <a href="language.types.php" class="link">types</a>
    </strong><br />
    <p class="para">
     Although PHP is a loosely typed language, it&#039;s important to have 
     a basic understanding of <a href="language.types.php" class="link">types</a> as 
     they have important meaning.
    </p>
   </p></blockquote>
   <p class="para">
    Function definitions tell us what 
    type of value is <a href="functions.returning-values.php" class="link">returned</a>.
    Let&#039;s use the definition for <span class="function"><a href="function.strlen.php" class="function">strlen()</a></span> as our first example:
   </p>
   <p class="para">
    <div class="example-contents screen">
<div class="cdata"><pre>
strlen

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

Description
strlen ( string $string ) : int

Returns the length of given string.
</pre></div>
    </div>
   </p>
   <p class="para">
    <table class="doctable table">
     <caption><strong>Explanation of a function definition</strong></caption>
      
       <thead>
        <tr>
         <th>Part</th>
         <th>Description</th>
        </tr>

       </thead>

       <tbody class="tbody">
        <tr>
         <td>
          strlen
         </td>
         <td>
          The function name.
         </td>
        </tr>

        <tr>
         <td>
          (PHP 4, PHP 5, PHP 7)
         </td>
         <td>
          strlen() has been around in all versions of PHP 4, 5 and 7
         </td>
        </tr>

        <tr>
         <td>
          ( string $string )
         </td>
         <td>
          The first (and in this case the only) parameter/argument for this
          function is named <code class="parameter">string</code>, and it&#039;s a
          <span class="type"><a href="language.types.string.php" class="type string">string</a></span>.
         </td>
        </tr>

        <tr>
         <td>
          int
         </td>
         <td>
          Type of value this function returns, which is an
          <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> (i.e. the length of a string is measured in
          numbers).
         </td>
        </tr>

       </tbody>
      
     </table>

    </p>
    <p class="para">
     We could rewrite the above function definition in a generic way:
    </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">
     Many functions take on multiple parameters, such as <span class="function"><a href="function.in-array.php" class="function">in_array()</a></span>.
     Its prototype is as follows:
    </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">
     What does this mean?  in_array() returns a 
     <a href="language.types.boolean.php" class="link">boolean</a> value, <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on 
     success (if the <code class="parameter">needle</code> was found in the 
     <code class="parameter">haystack</code>) or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure (if the 
     <code class="parameter">needle</code> was not found in the 
     <code class="parameter">haystack</code>).  The first parameter is named 
     <code class="parameter">needle</code> and it can be of many different 
     <a href="language.types.php" class="link">types</a>, so we call it 
     &quot;<em>mixed</em>&quot;.  This mixed <code class="parameter">needle</code> 
     (what we&#039;re looking for) can be either a scalar value (string, integer, 
     or <a href="language.types.float.php" class="link">float</a>), or an
     <a href="language.types.array.php" class="link">array</a>.
     <code class="parameter">haystack</code> (the array we&#039;re searching in) is the 
     second parameter.  The third <em>optional</em> parameter is 
     named <code class="parameter">strict</code>.  All optional parameters have default 
     values; if the default value is unknown, it is shown as <code class="literal">?</code>.  The manual 
     states that the <code class="parameter">strict</code> parameter defaults to 
     boolean <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.  See the manual page on each function for details on 
     how they work.
    </p>
    <p class="para"> 
     In addition the &amp; (ampersand) symbol prepended to a function parameter 
     allows the parameter to be passed by <a href="language.references.pass.php" class="link">reference</a>, as seen below: 
    </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">
     In this example, we can see the third optional parameter <code class="parameter">&amp;$matches</code> will be 
     passed as reference. 
    </p>
    <p class="para">
     There are also functions with more complex PHP version information. Take
     <span class="function"><a href="function.html-entity-decode.php" class="function">html_entity_decode()</a></span> as an example:
    </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">
     This means that this function has only been
     available in a released version since PHP 4.3.0. 
    </p>
 </div><?php manual_footer($setup); ?>