<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.classobj.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.property-exists.php',
    1 => 'property_exists',
    2 => 'Checks if the object or class has a property',
  ),
  'up' => 
  array (
    0 => 'ref.classobj.php',
    1 => 'Classes/Object Functions',
  ),
  'prev' => 
  array (
    0 => 'function.method-exists.php',
    1 => 'method_exists',
  ),
  'next' => 
  array (
    0 => 'function.trait-exists.php',
    1 => 'trait_exists',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/classobj/functions/property-exists.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.property-exists" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">property_exists</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">property_exists</span> &mdash; <span class="dc-title">
   Checks if the object or class has a property
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.property-exists-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>property_exists</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.object.php" class="type object">object</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$object_or_class</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$property</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   This function checks if the given <code class="parameter">property</code> exists in
   the specified class.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    As opposed with <span class="function"><a href="function.isset.php" class="function">isset()</a></span>,
    <span class="function"><strong>property_exists()</strong></span> returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> even if the property
    has the value <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.property-exists-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">object_or_class</code></dt>
      <dd>
       <p class="para">
        The class name or an object of the class to test for
       </p>
      </dd>
     
    
     <dt><code class="parameter">property</code></dt>
      <dd>
       <p class="para">
        The name of the property
       </p>
      </dd>
     
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.property-exists-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 the property exists, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if it doesn&#039;t exist.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.property-exists-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 A <span class="function"><strong>property_exists()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">myClass </span><span style="color: #007700">{<br />    public </span><span style="color: #0000BB">$mine</span><span style="color: #007700">;<br />    private </span><span style="color: #0000BB">$xpto</span><span style="color: #007700">;<br />    static protected </span><span style="color: #0000BB">$test</span><span style="color: #007700">;<br /><br />    static function </span><span style="color: #0000BB">test</span><span style="color: #007700">() {<br />        </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</span><span style="color: #007700">, </span><span style="color: #DD0000">'xpto'</span><span style="color: #007700">)); </span><span style="color: #FF8000">//true<br />    </span><span style="color: #007700">}<br />}<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</span><span style="color: #007700">, </span><span style="color: #DD0000">'mine'</span><span style="color: #007700">));   </span><span style="color: #FF8000">//true<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(new </span><span style="color: #0000BB">myClass</span><span style="color: #007700">, </span><span style="color: #DD0000">'mine'</span><span style="color: #007700">)); </span><span style="color: #FF8000">//true<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</span><span style="color: #007700">, </span><span style="color: #DD0000">'xpto'</span><span style="color: #007700">));   </span><span style="color: #FF8000">//true<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</span><span style="color: #007700">, </span><span style="color: #DD0000">'bar'</span><span style="color: #007700">));    </span><span style="color: #FF8000">//false<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</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">myClass</span><span style="color: #007700">::</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>
 </div>


 <div class="refsect1 notes" id="refsect1-function.property-exists-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
<p class="para">Using this function will use any registered
<a href="language.oop5.autoload.php" class="link">autoloaders</a> if the class is not already known.</p></p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    The <span class="function"><strong>property_exists()</strong></span> function cannot detect properties
    that are magically accessible using the <a href="language.oop5.overloading.php#language.oop5.overloading.members" class="link"><code class="literal">__get</code></a>
    magic method.
   </p>
  </p></blockquote>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.property-exists-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.method-exists.php" class="function" rel="rdfs-seeAlso">method_exists()</a> - Checks if the class method exists</span></li>
   </ul>
  </p>
 </div>

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