<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.reflectionclass.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'reflectionclass.getconstant.php',
    1 => 'ReflectionClass::getConstant',
    2 => '获取已定义的常量',
  ),
  'up' => 
  array (
    0 => 'class.reflectionclass.php',
    1 => 'ReflectionClass',
  ),
  'prev' => 
  array (
    0 => 'reflectionclass.getattributes.php',
    1 => 'ReflectionClass::getAttributes',
  ),
  'next' => 
  array (
    0 => 'reflectionclass.getconstants.php',
    1 => 'ReflectionClass::getConstants',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/reflection/reflectionclass/getconstant.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="reflectionclass.getconstant" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionClass::getConstant</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ReflectionClass::getConstant</span> &mdash; <span class="dc-title">获取已定义的常量</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionclass.getconstant-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionClass::getConstant</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="para rdfs-comment">
   获取已定义的常量。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionclass.getconstant-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">name</code></dt>
     <dd>
      <p class="para">
       要获取的类常量的名称。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionclass.getconstant-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   常量名称为 <code class="parameter">name</code> 的值。
   如果在类中没有找到该常量，则返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> 。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-reflectionclass.getconstant-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 使用 <span class="methodname"><strong>ReflectionClass::getConstant()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Example </span><span style="color: #007700">{<br />    const </span><span style="color: #0000BB">C1 </span><span style="color: #007700">= </span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />    const </span><span style="color: #0000BB">C2 </span><span style="color: #007700">= </span><span style="color: #DD0000">'I am a constant'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$reflection </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'Example'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getConstant</span><span style="color: #007700">(</span><span style="color: #DD0000">'C1'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getConstant</span><span style="color: #007700">(</span><span style="color: #DD0000">'C2'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getConstant</span><span style="color: #007700">(</span><span style="color: #DD0000">'C3'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(false)
string(15) &quot;I am a constant&quot;
bool(false)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionclass.getconstant-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="reflectionclass.getconstants.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::getConstants()</a> - 获取常量</span></li>
   </ul>
  </p>
 </div>


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