<?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 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.constant.php',
    1 => 'constant',
    2 => 'Ritorna il valore di una costante',
  ),
  'up' => 
  array (
    0 => 'ref.misc.php',
    1 => 'Misc. Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.connection-status.php',
    1 => 'connection_status',
  ),
  'next' => 
  array (
    0 => 'function.define.php',
    1 => 'define',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'reference/misc/functions/constant.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.constant" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">constant</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">constant</span> &mdash; <span class="dc-title">Ritorna il valore di una costante</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.constant-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>constant</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$name</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="simpara">
   Ritorna il valore di una costante di nome
   <code class="parameter">name</code>.
  </p>
  <p class="simpara">
   <span class="function"><strong>constant()</strong></span> è utile se si ha bisogno di ottenere
   il valore di una costante, ma non se ne conosce il nome. Per esempio se
   è in una variabile ritornata da una funzione.
  </p>
  <p class="simpara">
   Questa funzione può essere usata anche con le <a href="language.oop5.constants.php" class="link">costanti di classe</a>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.constant-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">name</code></dt>
     <dd>
      <p class="para">
       Il nome della costante.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.constant-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Ritorna il valore della costante o <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> se la costante non è 
   definita.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.constant-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="para">
   Un errore <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> e&#039; generato se la
   costante non è definita.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.constant-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Esempio d&#039;uso di <span class="function"><strong>constant()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">"MAXSIZE"</span><span style="color: #007700">, </span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">MAXSIZE</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">constant</span><span style="color: #007700">(</span><span style="color: #DD0000">"MAXSIZE"</span><span style="color: #007700">); </span><span style="color: #FF8000">// Equivalente alla riga precedente<br /><br /><br /></span><span style="color: #007700">interface </span><span style="color: #0000BB">bar </span><span style="color: #007700">{<br />    const </span><span style="color: #0000BB">test </span><span style="color: #007700">= </span><span style="color: #DD0000">'foobar!'</span><span style="color: #007700">;<br />}<br /><br />class </span><span style="color: #0000BB">foo </span><span style="color: #007700">{<br />    const </span><span style="color: #0000BB">test </span><span style="color: #007700">= </span><span style="color: #DD0000">'foobar!'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$const </span><span style="color: #007700">= </span><span style="color: #DD0000">'test'</span><span style="color: #007700">;<br /><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">'bar::'</span><span style="color: #007700">. </span><span style="color: #0000BB">$const</span><span style="color: #007700">)); </span><span style="color: #FF8000">// string(7) "foobar!"<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">'foo::'</span><span style="color: #007700">. </span><span style="color: #0000BB">$const</span><span style="color: #007700">)); </span><span style="color: #FF8000">// string(7) "foobar!"<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.constant-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.define.php" class="function" rel="rdfs-seeAlso">define()</a> - Definisce una costante</span></li>
    <li><span class="function"><a href="function.defined.php" class="function" rel="rdfs-seeAlso">defined()</a> - Verifica se dato nome di una costante, essa esiste</span></li>
    <li>La sezione <a href="language.constants.php" class="link">Costanti</a></li>
   </ul>
  </p>
 </div>


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