<!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>Returns an associative array with the names of all the constants and their values</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.get-current-user.html">get_current_user</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.get-extension-funcs.html">get_extension_funcs</a></div> <div class="up"><a href="ref.info.html">PHP Options/Info Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><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)</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="type">array</span> <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> ] )</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.html" 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> <span class="term"><em><code class="parameter">categorize</code></em></span> <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="cdata"><pre> 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> </dt> </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 changelog" id="refsect1-function.get-defined-constants-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.3.1</td> <td> Windows only: Core constants are categorized under <em>Core</em>, previously <em>mhash</em>. </td> </tr> <tr> <td>5.3.0</td> <td> Core constants are categorized under <em>Core</em>, previously <em>internal</em>. On Windows, the Core Constants are categorized under <em>mhash</em>. </td> </tr> <tr> <td>5.2.11</td> <td> The <em><code class="parameter">categorize</code></em> parameter now operates appropriately. Previously, the <em><code class="parameter">categorize</code></em> parameter was interpreted as <em>!is_null($categorize)</em>, making any value other than <strong><code>NULL</code></strong> force the constants to be categorized. </td> </tr> <tr> <td>5.0.0</td> <td> The <em><code class="parameter">categorize</code></em> parameter was added. </td> </tr> </tbody> </table> </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-486"> <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="cdata"><pre> 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 class="member"> <span class="function"><a href="function.defined.html" class="function" rel="rdfs-seeAlso">defined()</a> - Checks whether a given named constant exists</span></li> <li class="member"> <span class="function"><a href="function.get-loaded-extensions.html" class="function" rel="rdfs-seeAlso">get_loaded_extensions()</a> - Returns an array with the names of all modules compiled and loaded</span></li> <li class="member"> <span class="function"><a href="function.get-defined-functions.html" class="function" rel="rdfs-seeAlso">get_defined_functions()</a> - Returns an array of all defined functions</span></li> <li class="member"> <span class="function"><a href="function.get-defined-vars.html" class="function" rel="rdfs-seeAlso">get_defined_vars()</a> - Returns an array of all defined variables</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.get-current-user.html">get_current_user</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.get-extension-funcs.html">get_extension_funcs</a></div> <div class="up"><a href="ref.info.html">PHP Options/Info Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>