Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 8887

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Constants</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="language.variables.external.html">Variables From External Sources</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="language.constants.syntax.html">Syntax</a></div>
 <div class="up"><a href="langref.html">Language Reference</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="language.constants" class="chapter">
  <h1>Constants</h1>
<h2>Table of Contents</h2><ul class="chunklist chunklist_chapter"><li><a href="language.constants.syntax.html">Syntax</a></li><li><a href="language.constants.predefined.html">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.html" 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:
   <em>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*</em>
  </p>
  <div class="tip"><strong class="tip">Tip</strong><p class="simpara">See also the
<a href="userlandnaming.html" class="xref">Userland Naming Guide</a>.</p></div>
  <p class="para">
   <div class="example" id="example-112">
    <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">//&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>
  <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 127 through 255 (0x7f-0xff).
   </span>
  </p></blockquote>

  <p class="simpara">
   Like <a href="language.variables.predefined.html" 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.html" class="link">variable scope</a>.
  </p>

  
  
  
 </div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="language.variables.external.html">Variables From External Sources</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="language.constants.syntax.html">Syntax</a></div>
 <div class="up"><a href="langref.html">Language Reference</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>