📄 function.constant.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Returns the value of a constant</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.connection-timeout.html">connection_timeout</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.define.html">define</a></div> <div class="up"><a href="ref.misc.html">Misc. Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.constant" class="refentry"> <div class="refnamediv"> <h1 class="refname">constant</h1> <p class="verinfo">(PHP 4 >= 4.0.4, PHP 5)</p><p class="refpurpose"><span class="refname">constant</span> — <span class="dc-title">Returns the value of a constant</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>constant</b></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.html" class="link">class constants</a>. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">name</tt></i></span> <dd> <p class="para"> The constant name. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the value of the constant, or <b><tt>NULL</tt></b> if the constant is not defined. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>constant()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">"MAXSIZE"</span><span style="color: #007700">, </span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">MAXSIZE</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">constant</span><span style="color: #007700">(</span><span style="color: #DD0000">"MAXSIZE"</span><span style="color: #007700">); </span><span style="color: #FF8000">// same thing as the previous line<br /><br /><br /></span><span style="color: #007700">interface </span><span style="color: #0000BB">bar </span><span style="color: #007700">{<br /> const </span><span style="color: #0000BB">test </span><span style="color: #007700">= </span><span style="color: #DD0000">'foobar!'</span><span style="color: #007700">;<br />}<br /><br />class </span><span style="color: #0000BB">foo </span><span style="color: #007700">{<br /> const </span><span style="color: #0000BB">test </span><span style="color: #007700">= </span><span style="color: #DD0000">'foobar!'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$const </span><span style="color: #007700">= </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">. </span><span style="color: #0000BB">$const</span><span style="color: #007700">)); </span><span style="color: #FF8000">// string(7) "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">. </span><span style="color: #0000BB">$const</span><span style="color: #007700">)); </span><span style="color: #FF8000">// string(7) "foobar!"<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.define.html" class="function" rel="rdfs-seeAlso">define()</a></li> <li class="member"><a href="function.defined.html" class="function" rel="rdfs-seeAlso">defined()</a></li> <li class="member">The section on <a href="language.constants.html" class="link">Constants</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.connection-timeout.html">connection_timeout</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.define.html">define</a></div> <div class="up"><a href="ref.misc.html">Misc. Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -