downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/fr/language.pseudo-types.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/language.types.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'fr',
  ),
 
'this' =>
  array (
   
0 => 'language.pseudo-types.php',
   
1 => 'Variables et pseudo-types utilisés dans cette documentation',
  ),
 
'up' =>
  array (
   
0 => 'language.types.php',
   
1 => 'Les types',
  ),
 
'prev' =>
  array (
   
0 => 'language.types.null.php',
   
1 => 'NULL',
  ),
 
'next' =>
  array (
   
0 => 'language.types.type-juggling.php',
   
1 => 'Manipulation des types',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="language.pseudo-types" class="sect1">
 <h2 class="title">Variables et pseudo-types utilisés dans cette documentation</h2>

 <div id="language.types.mixed" class="sect2">
  <h3 class="title">mixed</h3>

  <p class="para">
   <i>mixed</i> indique qu&#039;un paramètre peut accepter plusieurs
   (mais pas nécessairement tous) types.
  </p>

  <p class="para">
   <a href="function.gettype.php" class="function">gettype()</a> par exemple, accepte tous les types PHP,
   alors que <a href="function.str-replace.php" class="function">str_replace()</a> accepte les chaînes et les
   tableaux.
  </p>

 </div>

 <div id="language.types.number" class="sect2">
  <h3 class="title">number</h3>

  <p class="para">
   <i>number</i> indique qu&#039;un paramètre peut être soit un nombre entier,
   soit un nombre décimal (<a href="language.types.float.php" class="link">nombre décimal</a>).
  </p>

 </div>

 <div id="language.types.callback" class="sect2">
  <h3 class="title">callback</h3>

  <p class="para">
   Quelques fonctions comme <a href="function.call-user-func.php" class="function">call_user_func()</a> ou
   <a href="function.usort.php" class="function">usort()</a> acceptent des fonctions de rappel définies par
   l&#039;utilisateur comme paramètre. Les fonctions de rappel peuvent ne pas être
   de simples fonctions, mais aussi des méthodes d&#039;objets, incluant des
   méthodes statiques.
  </p>

  <p class="para">
   Une fonction PHP est passée par son nom, comme une chaîne. N&#039;importe quelle
   fonction interne ou définie par l&#039;utilisateur peut être passée, excepté
   les constructeurs de langage comme :
   <a href="function.array.php" class="function">array()</a>, <a href="function.echo.php" class="function">echo()</a>,
   <a href="function.empty.php" class="function">empty()</a>, <a href="function.eval.php" class="function">eval()</a>,
   <a href="function.exit.php" class="function">exit()</a>, <a href="function.isset.php" class="function">isset()</a>,
   <a href="function.list.php" class="function">list()</a>, <a href="function.print.php" class="function">print()</a> ou
   <a href="function.unset.php" class="function">unset()</a>.
  </p>

  <p class="para">
   Une méthode d&#039;un objet instancié est passée comme étant un tableau,
   contenant un objet à l&#039;index 0 et le nom de la méthode à l&#039;index 1.
  </p>

  <p class="para">
   Les méthodes de classe statique peuvent également être passées sans
   instanciation de l&#039;objet, en passant le nom de la classe au lieu de l&#039;objet
   à l&#039;index 0.
  </p>

  <p class="para">
   Mise à part des fonctions définies par l&#039;utilisateur,
   <a href="function.create-function.php" class="function">create_function()</a> peut également être
   utilisée pour créer des fonctions de rappel anonymes.
   Depuis PHP 5.3.0, il est aussi possible de passer une
   fonction anonyme comme paramètre de rappel.
  </p>

  <p class="para">
      </p><div class="example">
      <p><b>Exemple #1 Exemples de fonctions de rappel</b></p>
      <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;<br /><br /></span><span style="color: #FF8000">//&nbsp;Un&nbsp;exemple&nbsp;de&nbsp;fonction&nbsp;de&nbsp;rappel<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">ma_fonction_callback</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Bonjour&nbsp;le&nbsp;monde&nbsp;!'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Un&nbsp;exemple&nbsp;de&nbsp;méthode&nbsp;de&nbsp;rappel<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">MaClasse&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">maMethodeCallback</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Bonjour&nbsp;le&nbsp;monde&nbsp;!'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Type&nbsp;1&nbsp;:&nbsp;Rappel&nbsp;simple<br /></span><span style="color: #0000BB">call_user_func</span><span style="color: #007700">(</span><span style="color: #DD0000">'ma_fonction_callback'</span><span style="color: #007700">);&nbsp;<br /><br /></span><span style="color: #FF8000">//&nbsp;Type&nbsp;2&nbsp;:&nbsp;Appel&nbsp;d'une&nbsp;méthode&nbsp;de&nbsp;classe&nbsp;statique<br /></span><span style="color: #0000BB">call_user_func</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'MaClasse'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'maMethodeCallback'</span><span style="color: #007700">));&nbsp;<br /><br /></span><span style="color: #FF8000">//&nbsp;Type&nbsp;3&nbsp;:&nbsp;Appel&nbsp;d'une&nbsp;méthode&nbsp;d'objet<br /></span><span style="color: #0000BB">$obj&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MaClasse</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">call_user_func</span><span style="color: #007700">(array(</span><span style="color: #0000BB">$obj</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'maMethodeCallback'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;Type&nbsp;4&nbsp;:&nbsp;Appel&nbsp;d'une&nbsp;méthode&nbsp;de&nbsp;classe&nbsp;statique&nbsp;(Depuis&nbsp;PHP&nbsp;5.2.3)<br /></span><span style="color: #0000BB">call_user_func</span><span style="color: #007700">(</span><span style="color: #DD0000">'MaClasse::maMethodeCallback'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Type&nbsp;5&nbsp;:&nbsp;Appel&nbsp;d'une&nbsp;méthode&nbsp;de&nbsp;classe&nbsp;statique&nbsp;relative&nbsp;(Depuis&nbsp;PHP&nbsp;5.3.0)<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">A&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">who</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"A\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />class&nbsp;</span><span style="color: #0000BB">B&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">A&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">who</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"B\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">call_user_func</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'B'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'parent::who'</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;A<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
  <p class="para">
   </p><div class="example">
    <p><b>Exemple #2
     Exemple de fonction anonyme comme fonction de rappel
    </b></p>
   <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;La&nbsp;fonction&nbsp;anonyme<br /></span><span style="color: #0000BB">$double&nbsp;</span><span style="color: #007700">=&nbsp;function(</span><span style="color: #0000BB">$a</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br />};<br /><br /></span><span style="color: #FF8000">//&nbsp;Un&nbsp;intervalle&nbsp;de&nbsp;nombres<br /></span><span style="color: #0000BB">$numbers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Utilise&nbsp;la&nbsp;fonction&nbsp;anoyme&nbsp;comme&nbsp;fonction&nbsp;de&nbsp;rappel<br />//&nbsp;pour&nbsp;doubler&nbsp;la&nbsp;taille&nbsp;de&nbsp;chaque&nbsp;élément<br /></span><span style="color: #0000BB">$new_numbers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_map</span><span style="color: #007700">(</span><span style="color: #0000BB">$double</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$numbers</span><span style="color: #007700">);<br /><br />print&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">'&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$new_numbers</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents para"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
2 4 6 8 10
</pre></div>
    </div>
   </div><p>
  </p>

  <blockquote><p><b class="note">Note</b>:
   <span class="simpara">
    En PHP 4, il est nécessaire d&#039;utiliser une référence pour créer une fonction
    de rappel qui pointe vers un objet, et non une copie de celui-ci. Pour plus
    de détails, reportez-vous à la section
    &quot;<a href="language.references.php" class="link">Explication sur les références</a>&quot;.
   </span>
  </p></blockquote>

 </div>

 <div id="language.types.void" class="sect2">
  <h3 class="title">void</h3>

  <p class="para">
   <i>void</i> comme type retourné signifie que la valeur retournée
   est inutile. <i>void</i> dans une liste de paramètre signifie que
   la fonction n&#039;accepte aucun paramètre.
  </p>

 </div>

 <div id="language.types.dotdotdot" class="sect2">
  <h3 class="title">...</h3>

  <p class="para">
   <i><tt class="parameter">$...</tt></i>
 dans le prototype d&#039;une fonction signifie
   &quot;<i>et bien plus...</i>&quot;. Ce nom de variable est utilisé
   lorsqu&#039;une fonction peut prendre un nombre indéfini d&#039;arguments.
  </p>

 </div>
</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites