uTools-Manuals/docs/php/get_defined_constants.html
2019-04-28 19:00:34 +08:00

205 lines
7.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>返回所有常量的关联数组,键是常量名,值是常量值</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.get-defined-constants" class="refentry">
<div class="refnamediv">
<h1 class="refname">get_defined_constants</h1>
<p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">get_defined_constants</span> &mdash; <span class="dc-title">返回所有常量的关联数组,键是常量名,值是常量值</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.get-defined-constants-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>get_defined_constants</strong></span>
([ <span class="methodparam"><span class="type">bool</span> <code class="parameter">$categorize</code><span class="initializer"> = false</span></span>
] ) : <span class="type">array</span></div>
<p class="para rdfs-comment">
返回当前所有已定义的常量名和值。
这包含 <span class="function"><a href="define.html" class="function">define()</a></span> 函数所创建的,也包含了所有扩展所创建的。
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.get-defined-constants-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">categorize</code></dt>
<dd>
<p class="para">
让此函数返回一个多维数组,分类为第一维的键名,常量和它们的值位于第二维。
<div class="informalexample">
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">"MY_CONSTANT"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">get_defined_constants</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<p class="para">以上例程的输出类似于:</p>
<div class="example-contents screen">
<div class="cdata"><pre>
Array
(
[Core] =&gt; Array
(
[E_ERROR] =&gt; 1
[E_WARNING] =&gt; 2
[E_PARSE] =&gt; 4
[E_NOTICE] =&gt; 8
[E_CORE_ERROR] =&gt; 16
[E_CORE_WARNING] =&gt; 32
[E_COMPILE_ERROR] =&gt; 64
[E_COMPILE_WARNING] =&gt; 128
[E_USER_ERROR] =&gt; 256
[E_USER_WARNING] =&gt; 512
[E_USER_NOTICE] =&gt; 1024
[E_ALL] =&gt; 2047
[TRUE] =&gt; 1
)
[pcre] =&gt; Array
(
[PREG_PATTERN_ORDER] =&gt; 1
[PREG_SET_ORDER] =&gt; 2
[PREG_OFFSET_CAPTURE] =&gt; 256
[PREG_SPLIT_NO_EMPTY] =&gt; 1
[PREG_SPLIT_DELIM_CAPTURE] =&gt; 2
[PREG_SPLIT_OFFSET_CAPTURE] =&gt; 4
[PREG_GREP_INVERT] =&gt; 1
)
[user] =&gt; Array
(
[MY_CONSTANT] =&gt; 1
)
)
</pre></div>
</div>
</div>
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.get-defined-constants-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
返回的数组为 常量名 =&gt; 常量值,也可以按注册变量的扩展名称来分组。
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.get-defined-constants-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>5.3.1</td>
<td>
仅作用于 Windows内核常量归类到 <em>Core</em>,之前是 <em>mhash</em>
</td>
</tr>
<tr>
<td>5.3.0</td>
<td>
内核常量归类为 <em>Core</em>,之前是 <em>internal</em>。在 Windows 上,内核常量归类到 <em>mhash</em>
</td>
</tr>
<tr>
<td>5.2.11</td>
<td>
<code class="parameter">categorize</code> 参数现在可以合适得被处理。
在此之前,<code class="parameter">categorize</code> 被解释为 <em>!is_null($categorize)</em>,导致任何非 <strong><code>NULL</code></strong> 的值会强制常量分类。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.get-defined-constants-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-496">
<p><strong>Example #1 <span class="function"><strong>get_defined_constants()</strong></span> 例子</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">get_defined_constants</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Array
(
[E_ERROR] =&gt; 1
[E_WARNING] =&gt; 2
[E_PARSE] =&gt; 4
[E_NOTICE] =&gt; 8
[E_CORE_ERROR] =&gt; 16
[E_CORE_WARNING] =&gt; 32
[E_COMPILE_ERROR] =&gt; 64
[E_COMPILE_WARNING] =&gt; 128
[E_USER_ERROR] =&gt; 256
[E_USER_WARNING] =&gt; 512
[E_USER_NOTICE] =&gt; 1024
[E_ALL] =&gt; 2047
[TRUE] =&gt; 1
)
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.get-defined-constants-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="defined.html" class="function" rel="rdfs-seeAlso">defined()</a> - 检查某个名称的常量是否存在</span></li>
<li class="member"><span class="function"><a href="get_loaded_extensions.html" class="function" rel="rdfs-seeAlso">get_loaded_extensions()</a> - 返回所有编译并加载模块名的 array</span></li>
<li class="member"><span class="function"><a href="get_defined_functions.html" class="function" rel="rdfs-seeAlso">get_defined_functions()</a> - 返回所有已定义函数的数组</span></li>
<li class="member"><span class="function"><a href="get_defined_vars.html" class="function" rel="rdfs-seeAlso">get_defined_vars()</a> - 返回由所有已定义变量所组成的数组</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>