downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.defined.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.misc.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.defined.php',
   
1 => 'defined',
  ),
 
'up' =>
  array (
   
0 => 'ref.misc.php',
   
1 => 'Misc. Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.define.php',
   
1 => 'define',
  ),
 
'next' =>
  array (
   
0 => 'function.die.php',
   
1 => 'die',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.defined" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">defined</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">defined</span> &mdash; <span class="dc-title">Checks whether a given named constant exists</span></p>

 </div>
 
 <a name="function.defined.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>defined</b></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$name</tt></span>
   )</div>

  <p class="para rdfs-comment">
   Checks whether the given constant exists and is defined.
  </p>
  <blockquote><p><b class="note">Note</b>:
  
    If you want to see if a variable exists, use <a href="function.isset.php" class="function">isset()</a>
    as <b>defined()</b> only applies to <a href="language.constants.php" class="link">constants</a>. If you want to see if a
    function exists, use <a href="function.function-exists.php" class="function">function_exists()</a>.
   <br />
  </p></blockquote>
 </div>


 <a name="function.defined.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">name</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The constant name.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.defined.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <b><tt class="constant">TRUE</tt></b> if the named constant given by <i><tt class="parameter">name</tt></i>

   has been defined, <b><tt class="constant">FALSE</tt></b> otherwise.
  </p>
 </div>


 <a name="function.defined.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 Checking Constants</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Note&nbsp;the&nbsp;use&nbsp;of&nbsp;quotes,&nbsp;this&nbsp;is&nbsp;important.&nbsp;&nbsp;This&nbsp;example&nbsp;is&nbsp;checking<br />&nbsp;*&nbsp;if&nbsp;the&nbsp;string&nbsp;'TEST'&nbsp;is&nbsp;the&nbsp;name&nbsp;of&nbsp;a&nbsp;constant&nbsp;named&nbsp;TEST&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">defined</span><span style="color: #007700">(</span><span style="color: #DD0000">'TEST'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">TEST</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div>


 <a name="function.defined.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.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"><a href="function.get-defined-constants.php" class="function" rel="rdfs-seeAlso">get_defined_constants()</a> - Returns an associative array with the names of all the constants and their values</li>
    <li class="member"><a href="function.function-exists.php" class="function" rel="rdfs-seeAlso">function_exists()</a> - Return TRUE if the given function has been defined</li>
    <li class="member">The section on <a href="language.constants.php" class="link">Constants</a></li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites