Source of: /manual/en/function.apc-define-constants.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.apc.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.apc-define-constants.php',
1 => 'apc_define_constants',
),
'up' =>
array (
0 => 'ref.apc.php',
1 => 'APC Functions',
),
'prev' =>
array (
0 => 'function.apc-compile-file.php',
1 => 'apc_compile_file',
),
'next' =>
array (
0 => 'function.apc-delete.php',
1 => 'apc_delete',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.apc-define-constants" class="refentry">
<div class="refnamediv">
<h1 class="refname">apc_define_constants</h1>
<p class="verinfo">(PECL apc >= 3.0.0)</p><p class="refpurpose"><span class="refname">apc_define_constants</span> — <span class="dc-title">
Defines a set of constants for retrieval and mass-definition
</span></p>
</div>
<a name="function.apc-define-constants.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>apc_define_constants</b></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$key</tt></span>
, <span class="methodparam"><span class="type">array</span> <tt class="parameter">$constants</tt></span>
[, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$case_sensitive</tt><span class="initializer"> = true</span></span>
] )</div>
<p class="para rdfs-comment">
<a href="function.define.php" class="function">define()</a> is notoriously slow. Since the main benefit of
APC is to increase the performance of scripts/applications, this mechanism
is provided to streamline the process of mass constant definition. However,
this function does not perform as well as anticipated.
</p>
<p class="para">
For a better-performing solution, try the
<a href="http://pecl.php.net/package/hidef" class="link external">» hidef</a> extension from PECL.
</p>
<blockquote><p><b class="note">Note</b>:
<span class="simpara">
To remove a set of stored constants (without clearing the entire cache), an
empty array may be passed as the <i><tt class="parameter">constants</tt></i>
parameter, effectively clearing the stored value(s).
</span>
</p></blockquote>
</div>
<a name="function.apc-define-constants.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">key</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The <i><tt class="parameter">key</tt></i>
serves as the name of the constant set
being stored. This <i><tt class="parameter">key</tt></i>
is used to retrieve the
stored constants in <a href="function.apc-load-constants.php" class="function">apc_load_constants()</a>.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">constants</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
An associative array of <i>constant_name => value</i>
pairs. The <i>constant_name</i> must follow the normal
<a href="language.constants.php" class="link">constant</a> naming rules.
<i>value</i> must evaluate to a scalar value.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">case_sensitive</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The default behaviour for constants is to be declared case-sensitive;
i.e. <i>CONSTANT</i> and <i>Constant</i>
represent different values. If this parameter evaluates to <b><tt class="constant">FALSE</tt></b> the
constants will be declared as case-insensitive symbols.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.apc-define-constants.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns <b><tt class="constant">TRUE</tt></b> on success or <b><tt class="constant">FALSE</tt></b> on failure.
</p>
</div>
<a name="function.apc-define-constants.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 <b>apc_define_constants()</b> example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br />$constants </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'ONE' </span><span style="color: #007700">=> </span><span style="color: #0000BB">1</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'TWO' </span><span style="color: #007700">=> </span><span style="color: #0000BB">2</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'THREE' </span><span style="color: #007700">=> </span><span style="color: #0000BB">3</span><span style="color: #007700">,<br />);<br /></span><span style="color: #0000BB">apc_define_constants</span><span style="color: #007700">(</span><span style="color: #DD0000">'numbers'</span><span style="color: #007700">, </span><span style="color: #0000BB">$constants</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">ONE</span><span style="color: #007700">, </span><span style="color: #0000BB">TWO</span><span style="color: #007700">, </span><span style="color: #0000BB">THREE</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<div class="example-contents para"><p>The above example will output:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
123
</pre></div>
</div>
</div><p>
</p>
</div>
<a name="function.apc-define-constants.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.apc-load-constants.php" class="function" rel="rdfs-seeAlso">apc_load_constants()</a> - Loads a set of constants from the cache</li>
<li class="member"><a href="function.define.php" class="function" rel="rdfs-seeAlso">define()</a> - Defines a named constant</li>
<li class="member"><a href="function.constant.php" class="function" rel="rdfs-seeAlso">constant()</a> - Returns the value of a constant</li>
<li class="member">
Or <a href="language.constants.php" class="link">the PHP constants reference</a>
</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>