<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc'; $TOC = array(); $TOC_DEPRECATED = array(); $PARENTS = array(); include_once dirname(__FILE__) ."/toc/ref.info.inc"; $setup = array ( 'home' => array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'function.get-defined-constants.php', 1 => 'get_defined_constants', 2 => 'Returns an associative array with the names of all the constants and their values', ), 'up' => array ( 0 => 'ref.info.php', 1 => 'PHP Options/Info Functions', ), 'prev' => array ( 0 => 'function.get-current-user.php', 1 => 'get_current_user', ), 'next' => array ( 0 => 'function.get-extension-funcs.php', 1 => 'get_extension_funcs', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/info/functions/get-defined-constants.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?> <div id="function.get-defined-constants" class="refentry"> <div class="refnamediv"> <h1 class="refname">get_defined_constants</h1> <p class="verinfo">(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">get_defined_constants</span> — <span class="dc-title">Returns an associative array with the names of all the constants and their values</span></p> </div> <div class="refsect1 description" id="refsect1-function.get-defined-constants-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="methodname"><strong>get_defined_constants</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$categorize</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div> <p class="para rdfs-comment"> Returns the names and values of all the constants currently defined. This includes those created by extensions as well as those created with the <span class="function"><a href="function.define.php" class="function">define()</a></span> function. </p> </div> <div class="refsect1 parameters" id="refsect1-function.get-defined-constants-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt><code class="parameter">categorize</code></dt> <dd> <p class="para"> Causing this function to return a multi-dimensional array with categories in the keys of the first dimension and constants and their values in the second dimension. <div class="informalexample"> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">"MY_CONSTANT"</span><span style="color: #007700">, </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">?></span></span></code></div> </div> <p class="para">The above example will output something similar to:</p> <div class="example-contents screen"> <div class="parameterscode"><pre class="parameterscode">Array ( [Core] => Array ( [E_ERROR] => 1 [E_WARNING] => 2 [E_PARSE] => 4 [E_NOTICE] => 8 [E_CORE_ERROR] => 16 [E_CORE_WARNING] => 32 [E_COMPILE_ERROR] => 64 [E_COMPILE_WARNING] => 128 [E_USER_ERROR] => 256 [E_USER_WARNING] => 512 [E_USER_NOTICE] => 1024 [E_ALL] => 2047 [TRUE] => 1 ) [pcre] => Array ( [PREG_PATTERN_ORDER] => 1 [PREG_SET_ORDER] => 2 [PREG_OFFSET_CAPTURE] => 256 [PREG_SPLIT_NO_EMPTY] => 1 [PREG_SPLIT_DELIM_CAPTURE] => 2 [PREG_SPLIT_OFFSET_CAPTURE] => 4 [PREG_GREP_INVERT] => 1 ) [user] => Array ( [MY_CONSTANT] => 1 ) )</pre> </div> </div> </div> </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.get-defined-constants-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an array of constant name => constant value array, optionally groupped by extension name registering the constant. </p> </div> <div class="refsect1 examples" id="refsect1-function.get-defined-constants-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-642"> <p><strong>Example #1 <span class="function"><strong>get_defined_constants()</strong></span> Example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?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">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="examplescode"><pre class="examplescode">Array ( [E_ERROR] => 1 [E_WARNING] => 2 [E_PARSE] => 4 [E_NOTICE] => 8 [E_CORE_ERROR] => 16 [E_CORE_WARNING] => 32 [E_COMPILE_ERROR] => 64 [E_COMPILE_WARNING] => 128 [E_USER_ERROR] => 256 [E_USER_WARNING] => 512 [E_USER_NOTICE] => 1024 [E_ALL] => 2047 [TRUE] => 1 )</pre> </div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.get-defined-constants-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li><span class="function"><a href="function.defined.php" class="function" rel="rdfs-seeAlso">defined()</a> - Checks whether a constant with the given name exists</span></li> <li><span class="function"><a href="function.constant.php" class="function" rel="rdfs-seeAlso">constant()</a> - Returns the value of a constant</span></li> <li><span class="function"><a href="function.get-loaded-extensions.php" class="function" rel="rdfs-seeAlso">get_loaded_extensions()</a> - Returns an array with the names of all modules compiled and loaded</span></li> <li><span class="function"><a href="function.get-defined-functions.php" class="function" rel="rdfs-seeAlso">get_defined_functions()</a> - Returns an array of all defined functions</span></li> <li><span class="function"><a href="function.get-defined-vars.php" class="function" rel="rdfs-seeAlso">get_defined_vars()</a> - Returns an array of all defined variables</span></li> </ul> </p> </div> </div><?php manual_footer($setup); ?>