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/en/function.constant.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.constant.php',
   
1 => 'constant',
  ),
 
'up' =>
  array (
   
0 => 'ref.misc.php',
   
1 => 'Misc. Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.connection-timeout.php',
   
1 => 'connection_timeout',
  ),
 
'next' =>
  array (
   
0 => 'function.define.php',
   
1 => 'define',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<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)</p><p class="refpurpose"><span class="refname">constant</span> &mdash; <span class="dc-title">Returns the value of a constant</span></p>

 </div>
 
 <a name="function.constant.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b>constant</b></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$name</tt></span>
   )</div>

  <p class="simpara">
   Return the value of the constant indicated by
   <i><tt class="parameter">name</tt></i>
.
  </p>
  <p class="simpara">
   <b>constant()</b> is useful if you need to retrieve
   the value of a constant, but do not know its name.  I.e. it is
   stored in a variable or returned by a function.
  </p>
  <p class="simpara">
   This function works also with <a href="language.oop5.constants.php" class="link">class constants</a>.
  </p>
 </div>


 <a name="function.constant.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">name</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The constant name.
      </p>
     </dd>

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


 <a name="function.constant.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the value of the constant, or <b><tt class="constant">NULL</tt></b> if the constant is not
   defined.
  </p>
 </div>


 <a name="function.constant.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>constant()</b> example</b></p>
    <div class="example-contents programlisting">
<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">,&nbsp;</span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">MAXSIZE</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">constant</span><span style="color: #007700">(</span><span style="color: #DD0000">"MAXSIZE"</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;same&nbsp;thing&nbsp;as&nbsp;the&nbsp;previous&nbsp;line<br /><br /><br /></span><span style="color: #007700">interface&nbsp;</span><span style="color: #0000BB">bar&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">test&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'foobar!'</span><span style="color: #007700">;<br />}<br /><br />class&nbsp;</span><span style="color: #0000BB">foo&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">test&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'foobar!'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$const&nbsp;</span><span style="color: #007700">=&nbsp;</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">.&nbsp;</span><span style="color: #0000BB">$const</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;string(7)&nbsp;"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">.&nbsp;</span><span style="color: #0000BB">$const</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;string(7)&nbsp;"foobar!"<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

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


 <a name="function.constant.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.define.php" class="function" rel="rdfs-seeAlso">define()</a> - Defines a named constant</li>
    <li class="member"><a href="function.defined.php" class="function" rel="rdfs-seeAlso">defined()</a> - Checks whether a given named constant exists</li>
    <li class="member">The section on <a href="language.constants.php" class="link">Constants</a></li>
   </ul><p>
  </p>
 </div>


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