<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.misc.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.define.php',
    1 => 'define',
    2 => 'D&eacute;finit une constante',
  ),
  'up' => 
  array (
    0 => 'ref.misc.php',
    1 => 'Fonctions diverses',
  ),
  'prev' => 
  array (
    0 => 'function.constant.php',
    1 => 'constant',
  ),
  'next' => 
  array (
    0 => 'function.defined.php',
    1 => 'defined',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/misc/functions/define.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.define" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">define</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">define</span> &mdash; <span class="dc-title">Définit une constante</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.define-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>define</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$constant_name</code></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="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$case_insensitive</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Définit une constante à l&#039;exécution.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.define-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">constant_name</code></dt>
     <dd>
      <p class="para">
       Le nom de la constante.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        Il est possible de définir avec <span class="function"><strong>define()</strong></span> des constantes
        avec des noms réservés ou même invalides, où leurs valeurs peuvent (seulement)
        être récupérées avec la fonction <span class="function"><a href="function.constant.php" class="function">constant()</a></span>.
        Cependant, faire ceci n&#039;est pas recommandé.
       </p>
      </p></blockquote>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       La valeur de la constante.
      </p>
      <div class="warning"><strong class="warning">Avertissement</strong>
       <p class="para">
        Bien qu&#039;il soit techniquement possible de définir des constantes de type 
        <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>, ceci est déconseillé et peut causer des comportements inattendus.
       </p>
      </div>
     </dd>
    
    
     <dt><code class="parameter">case_insensitive</code></dt>
     <dd>
      <p class="para">
       S&#039;il vaut <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, la constante sera définie de manière insensible à la casse.
       Le comportement par défaut est sensible à la casse, c.-à-d. que
       <code class="literal">CONSTANT</code> et <code class="literal">Constant</code>
       représentent des valeurs différentes.
      </p>
      <div class="warning"><strong class="warning">Avertissement</strong>
       <p class="simpara">
        Définir des constantes insensibles à la casse est obsolète à partir de PHP 7.3.0.
        À partir de PHP 8.0.0, seul <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> est une valeur acceptable,
        passer <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> produira un avertissement.
       </p>
      </div>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        Les constantes insensibles à la casse sont stockées en minuscule.
       </p>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.define-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Cette fonction retourne <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> en cas de succès ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si une erreur survient.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.define-changelog">
  <h3 class="title">Historique</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.1.0</td>
       <td>
        <code class="parameter">value</code> peut désormais être un objet.
       </td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        Passer <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> à <code class="parameter">case_insensitive</code> émet désormais une <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
        Passer <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> est toujours autorisé.
       </td>
      </tr>

      <tr>
       <td>7.3.0</td>
       <td>
        <code class="parameter">case_insensitive</code> est obsolète et sera supprimée dans la version 8.0.0.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.define-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Définition d&#039;une constante</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">"CONSTANT"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Bonjour le monde."</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">CONSTANT</span><span style="color: #007700">; </span><span style="color: #FF8000">// affiche "Bonjour le monde."<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">Constant</span><span style="color: #007700">; </span><span style="color: #FF8000">// affiche "Constant" et émet une alerte<br /><br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"GREETING"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Salut toi."</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">GREETING</span><span style="color: #007700">; </span><span style="color: #FF8000">// affiche "Salut toi."<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">Greeting</span><span style="color: #007700">; </span><span style="color: #FF8000">// affiche "Salut toi."<br /><br />// Fonctionne à partir de PHP 7<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'ANIMALS'</span><span style="color: #007700">, array(<br />    </span><span style="color: #DD0000">'chien'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'chat'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'oiseaux'<br /></span><span style="color: #007700">));<br />echo </span><span style="color: #0000BB">ANIMALS</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]; </span><span style="color: #FF8000">// affiche "chat"<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Constantes avec des Noms Réservés</strong></p>
    <div class="example-contents"><p>
     Cet exemple illustre la <em>possibilité</em> de définir une
     constante avec le même nom qu&#039;une
     <a href="language.constants.magic.php" class="link">constante magique</a>.
     Puisque le comportement qui en résulte porte à confusion, cette pratique
     n&#039;est pas recommandée.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">defined</span><span style="color: #007700">(</span><span style="color: #DD0000">'__LINE__'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'__LINE__'</span><span style="color: #007700">, </span><span style="color: #DD0000">'test'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">constant</span><span style="color: #007700">(</span><span style="color: #DD0000">'__LINE__'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">__LINE__</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">bool(false)
bool(true)
string(4) &quot;test&quot;
int(5)</pre>
</div>
   </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.define-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.defined.php" class="function" rel="rdfs-seeAlso">defined()</a> - V&eacute;rifie si une constante avec le nom donn&eacute; existe</span></li>
    <li><span class="function"><a href="function.constant.php" class="function" rel="rdfs-seeAlso">constant()</a> - Retourne la valeur d'une constante</span></li>
    <li>La section sur les <a href="language.constants.php" class="link">constantes</a></li>
   </ul>
  </p>
 </div>


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