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/language.constants.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/langref.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'language.constants.php',
   
1 => 'Constants',
  ),
 
'up' =>
  array (
   
0 => 'langref.php',
   
1 => 'Language Reference',
  ),
 
'prev' =>
  array (
   
0 => 'language.variables.external.php',
   
1 => 'Variables From External Sources',
  ),
 
'next' =>
  array (
   
0 => 'language.constants.syntax.php',
   
1 => 'Syntax',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div>
  <h1>Constants</h1>
<h2>Table of Contents</h2><ul class="chunklist chunklist_chapter"><li><a href="language.constants.syntax.php">Syntax</a></li><li><a href="language.constants.predefined.php">Magic constants</a></li></ul>


  <p class="simpara">
   A constant is an identifier (name) for a simple value. As the name
   suggests, that value cannot change during the execution of the
   script (except for <a href="language.constants.predefined.php" class="link">
   magic constants</a>, which aren&#039;t actually constants).
   A constant is case-sensitive by default. By convention, constant
   identifiers are always uppercase.
  </p>
  <p class="para">
   The name of a constant follows the same rules as any label in PHP. A
   valid constant name starts with a letter or underscore, followed
   by any number of letters, numbers, or underscores. As a regular
   expression, it would be expressed thusly:
   <i>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*</i>
  </p>
  <div class="tip"><b class="tip">Tip</b><p class="simpara">See also the
<a href="userlandnaming.php" class="xref">Userland Naming Guide</a>.</p></div>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 Valid and invalid constant names</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;Valid&nbsp;constant&nbsp;names<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"FOO"</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"something"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"FOO2"</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"something&nbsp;else"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"FOO_BAR"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"something&nbsp;more"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Invalid&nbsp;constant&nbsp;names<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"2FOO"</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"something"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;This&nbsp;is&nbsp;valid,&nbsp;but&nbsp;should&nbsp;be&nbsp;avoided:<br />//&nbsp;PHP&nbsp;may&nbsp;one&nbsp;day&nbsp;provide&nbsp;a&nbsp;magical&nbsp;constant<br />//&nbsp;that&nbsp;will&nbsp;break&nbsp;your&nbsp;script<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"__FOO__"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"something"</span><span style="color: #007700">);&nbsp;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
  <blockquote><p><b class="note">Note</b>:
   <span class="simpara">
    For our purposes here, a letter is a-z, A-Z, and the ASCII
    characters from 127 through 255 (0x7f-0xff).
   </span>
  </p></blockquote>

  <p class="simpara">
   Like <a href="language.variables.predefined.php" class="link">superglobals</a>, the scope of a constant is global.  You
   can access constants anywhere in your script without regard to scope. 
   For more information on scope, read the manual section on
   <a href="language.variables.scope.php" class="link">variable scope</a>.
  </p>

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