<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.var.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.isset.php',
    1 => 'isset',
    2 => 'Determine if a variable is declared and is different than null',
  ),
  'up' => 
  array (
    0 => 'ref.var.php',
    1 => 'Variable handling Functions',
  ),
  'prev' => 
  array (
    0 => 'function.is-string.php',
    1 => 'is_string',
  ),
  'next' => 
  array (
    0 => 'function.print-r.php',
    1 => 'print_r',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/var/functions/isset.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.isset" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">isset</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">isset</span> &mdash; <span class="dc-title">Determine if a variable is declared and is different than <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.isset-description">
 <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>isset</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$var</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">...$vars</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Determine if a variable is considered set,
   this means if a variable is declared and is different than <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
  </p>
  <p class="para">
   If a variable has been unset with the <span class="function"><a href="function.unset.php" class="function">unset()</a></span>
   function, it is no longer considered to be set.
  </p>
  <p class="para">
   <span class="function"><strong>isset()</strong></span> will return <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> when checking a
   variable that has been assigned to <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
   Also note that a null character (<code class="literal">&quot;\0&quot;</code>) is not
   equivalent to the PHP <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> constant.
  </p>
  <p class="para">
   If multiple parameters are supplied then <span class="function"><strong>isset()</strong></span>
   will return <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> only if all of the parameters are considered set.
   Evaluation goes from left to right and stops as soon as an unset
   variable is encountered.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.isset-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">var</code></dt>
     <dd>
      <p class="para">
       The variable to be checked.
      </p>
     </dd>
    
    
     <dt><code class="parameter">vars</code></dt>
     <dd>
      <p class="para">
       Further variables.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.isset-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> if <code class="parameter">var</code> exists and has
   any value other than <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>. <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> otherwise.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.isset-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>isset()</strong></span> Examples</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$var </span><span style="color: #007700">= </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// This will evaluate to TRUE so the text will be printed.<br /></span><span style="color: #007700">if (isset(</span><span style="color: #0000BB">$var</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"This var is set so I will print."</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// In the next examples we'll use var_dump to output<br />// the return value of isset().<br /><br /></span><span style="color: #0000BB">$a </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$b </span><span style="color: #007700">= </span><span style="color: #DD0000">"anothertest"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">));      </span><span style="color: #FF8000">// TRUE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">, </span><span style="color: #0000BB">$b</span><span style="color: #007700">)); </span><span style="color: #FF8000">// TRUE<br /><br /></span><span style="color: #007700">unset (</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">));     </span><span style="color: #FF8000">// FALSE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">, </span><span style="color: #0000BB">$b</span><span style="color: #007700">)); </span><span style="color: #FF8000">// FALSE<br /><br /></span><span style="color: #0000BB">$foo </span><span style="color: #007700">= </span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">));   </span><span style="color: #FF8000">// FALSE<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   This also work for elements in arrays:
   <div class="example" id="example-2">
    <p><strong>Example #2 Example of <span class="function"><strong>isset()</strong></span> with array elements</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$a </span><span style="color: #007700">= array (</span><span style="color: #DD0000">'test' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">'hello' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">NULL</span><span style="color: #007700">, </span><span style="color: #DD0000">'pie' </span><span style="color: #007700">=&gt; array(</span><span style="color: #DD0000">'a' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'apple'</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[</span><span style="color: #DD0000">'test'</span><span style="color: #007700">]));            </span><span style="color: #FF8000">// TRUE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">]));             </span><span style="color: #FF8000">// FALSE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">]));           </span><span style="color: #FF8000">// FALSE<br /><br />// The key 'hello' equals NULL so is considered unset<br />// If you want to check for NULL key values then try: <br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">array_key_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">, </span><span style="color: #0000BB">$a</span><span style="color: #007700">)); </span><span style="color: #FF8000">// TRUE<br /><br />// Checking deeper array values<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[</span><span style="color: #DD0000">'pie'</span><span style="color: #007700">][</span><span style="color: #DD0000">'a'</span><span style="color: #007700">]));        </span><span style="color: #FF8000">// TRUE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[</span><span style="color: #DD0000">'pie'</span><span style="color: #007700">][</span><span style="color: #DD0000">'b'</span><span style="color: #007700">]));        </span><span style="color: #FF8000">// FALSE<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$a</span><span style="color: #007700">[</span><span style="color: #DD0000">'cake'</span><span style="color: #007700">][</span><span style="color: #DD0000">'a'</span><span style="color: #007700">][</span><span style="color: #DD0000">'b'</span><span style="color: #007700">]));  </span><span style="color: #FF8000">// FALSE<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <div class="example" id="example-3">
   <p><strong>Example #3 <span class="function"><strong>isset()</strong></span> on String Offsets</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$expected_array_got_string </span><span style="color: #007700">= </span><span style="color: #DD0000">'somestring'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$expected_array_got_string</span><span style="color: #007700">[</span><span style="color: #DD0000">'some_key'</span><span style="color: #007700">]));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$expected_array_got_string</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$expected_array_got_string</span><span style="color: #007700">[</span><span style="color: #DD0000">'0'</span><span style="color: #007700">]));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$expected_array_got_string</span><span style="color: #007700">[</span><span style="color: #0000BB">0.5</span><span style="color: #007700">]));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$expected_array_got_string</span><span style="color: #007700">[</span><span style="color: #DD0000">'0.5'</span><span style="color: #007700">]));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$expected_array_got_string</span><span style="color: #007700">[</span><span style="color: #DD0000">'0 Mostel'</span><span style="color: #007700">]));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output:</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(false)
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.isset-notes">
  <h3 class="title">Notes</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    <span class="function"><strong>isset()</strong></span> only works with variables as passing anything
    else will result in a parse error.  For checking if 
    <a href="language.constants.php" class="link">constants</a> are set use the 
    <span class="function"><a href="function.defined.php" class="function">defined()</a></span> function.
   </p>
  </div>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">Because this is a
language construct and not a function, it cannot be called using
<a href="functions.variable-functions.php" class="link">variable functions</a>,
or <a href="functions.arguments.php#functions.named-arguments" class="link">named arguments</a>.</span>
</p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    When using <span class="function"><strong>isset()</strong></span> on inaccessible object properties,
    the <a href="language.oop5.overloading.php#object.isset" class="link">__isset()</a>
    overloading method will be called, if declared.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.isset-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.empty.php" class="function" rel="rdfs-seeAlso">empty()</a> - Determine whether a variable is empty</span></li>
    <li><a href="language.oop5.overloading.php#object.isset" class="link">__isset()</a></li>
    <li><span class="function"><a href="function.unset.php" class="function" rel="rdfs-seeAlso">unset()</a> - unset a given variable</span></li>
    <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><a href="types.comparisons.php" class="link">the type comparison tables</a></li>
    <li><span class="function"><a href="function.array-key-exists.php" class="function" rel="rdfs-seeAlso">array_key_exists()</a> - Checks if the given key or index exists in the array</span></li>
    <li><span class="function"><a href="function.is-null.php" class="function" rel="rdfs-seeAlso">is_null()</a> - Finds whether a variable is null</span></li>
    <li>the error control <a href="language.operators.errorcontrol.php" class="link">@</a> operator</li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>