<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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',
    2 => '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',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/constants.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/language.constants.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.constants" class="chapter">
  <h1 class="title">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">Predefined constants</a></li><li><a href="language.constants.magic.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.magic.php" class="link">
   magic constants</a>, which aren&#039;t actually constants).
   Constants are case-sensitive. By convention, constant
   identifiers are always uppercase.
  </p>

  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Prior to PHP 8.0.0, constants defined using the <span class="function"><a href="function.define.php" class="function">define()</a></span>
    function may be case-insensitive.
   </p>
  </p></blockquote>

  <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:
   <code class="code">^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$</code>
  </p>
  <p class="para">
   It is possible to <span class="function"><a href="function.define.php" class="function">define()</a></span> constants with reserved or even
   invalid names, whose value can only be retrieved with the
   <span class="function"><a href="function.constant.php" class="function">constant()</a></span> function. However, doing so is not recommended.
  </p>
  <div class="tip"><strong class="tip">Tip</strong><p class="simpara">See also the
<a href="userlandnaming.php" class="xref">Userland Naming Guide</a>.</p></div>
  <p class="para">

   <div class="example" id="example-1">
    <p><strong>Example #1 Valid and invalid constant names</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// Valid constant names<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"FOO"</span><span style="color: #007700">,     </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">,    </span><span style="color: #DD0000">"something 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">, </span><span style="color: #DD0000">"something more"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Invalid constant names<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"2FOO"</span><span style="color: #007700">,    </span><span style="color: #DD0000">"something"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// This is valid, but should be avoided:<br />// PHP may one day provide a magical constant<br />// that will break your script<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"__FOO__"</span><span style="color: #007700">, </span><span style="color: #DD0000">"something"</span><span style="color: #007700">); <br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    For our purposes here, a letter is a-z, A-Z, and the ASCII
    characters from 128 through 255 (0x80-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.
   Constants can be accessed from anywhere in a 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>

  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    As of PHP 7.1.0, class constant may declare a visibility of protected
    or private, making them only available in the hierarchical scope of the
    class in which it is defined.
   </span>
  </p></blockquote>

  
  
  

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