<?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 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'function.class-exists.php',
    1 => 'class_exists',
    2 => 'Verifica se uma classe foi definida',
  ),
  'up' => 
  array (
    0 => 'ref.classobj.php',
    1 => 'Fun&ccedil;&otilde;es para Classes/Objetos',
  ),
  'prev' => 
  array (
    0 => 'function.class-alias.php',
    1 => 'class_alias',
  ),
  'next' => 
  array (
    0 => 'function.enum-exists.php',
    1 => 'enum_exists',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'pt_BR',
    'path' => 'reference/classobj/functions/class-exists.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.class-exists" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">class_exists</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">class_exists</span> &mdash; <span class="dc-title">Verifica se uma classe foi definida</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.class-exists-description">
  <h3 class="title">Descrição</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>class_exists</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$class</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$autoload</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Esta função verifica se uma classe foi definida.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.class-exists-parameters">
  <h3 class="title">Parâmetros</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">class</code></dt>
     <dd>
      <p class="para">
       O nome da classe. O nome da classe é verificada sem fazer distinção de maiúscula e minúscula.
      </p>
     </dd>
    
    
     <dt><code class="parameter">autoload</code></dt>
     <dd>
      <p class="para">
       Se deve-se <a href="language.oop5.autoload.php" class="link">carregar automaticamente</a>
       caso não tenha sido carregada.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.class-exists-returnvalues">
  <h3 class="title">Valor Retornado</h3>
  <p class="para">
   Retorna <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> se <code class="parameter">class</code> é uma classe definida,
   caso contrário retorna <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.class-exists-examples">
  <h3 class="title">Exemplos</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemplo #1 Exemplo de <span class="function"><strong>class_exists()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Verifica que a classe existe antes de se tentar usá-la<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">class_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'MinhaClasse'</span><span style="color: #007700">)) {<br />    </span><span style="color: #0000BB">$minhaclasse </span><span style="color: #007700">= new </span><span style="color: #0000BB">MinhaClasse</span><span style="color: #007700">();<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <div class="example" id="example-2">
    <p><strong>Exemplo #2 Exemplo do parâmetro <code class="parameter">autoload</code></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />spl_autoload_register</span><span style="color: #007700">(function (</span><span style="color: #0000BB">$nome_classe</span><span style="color: #007700">) {<br />    include </span><span style="color: #0000BB">$nome_classe </span><span style="color: #007700">. </span><span style="color: #DD0000">'.php'</span><span style="color: #007700">;<br /><br />    </span><span style="color: #FF8000">// Verifica se o arquivo incluído declarou a classe<br />    </span><span style="color: #007700">if (!</span><span style="color: #0000BB">class_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">$nome_classe</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">)) {<br />        throw new </span><span style="color: #0000BB">LogicException</span><span style="color: #007700">(</span><span style="color: #DD0000">"Não foi possível carregar a classe: </span><span style="color: #0000BB">$nome_classe</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br />    }<br />});<br /><br />if (</span><span style="color: #0000BB">class_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">MinhaClasse</span><span style="color: #007700">::class)) {<br />    </span><span style="color: #0000BB">$minhaclasse </span><span style="color: #007700">= new </span><span style="color: #0000BB">MinhaClasse</span><span style="color: #007700">();<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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

 <div class="refsect1 seealso" id="refsect1-function.class-exists-seealso">
  <h3 class="title">Veja Também</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.function-exists.php" class="function" rel="rdfs-seeAlso">function_exists()</a> - Retorna true se a fun&ccedil;&atilde;o informada estiver definida</span></li>
    <li><span class="function"><a href="function.enum-exists.php" class="function" rel="rdfs-seeAlso">enum_exists()</a> - Verifica se uma enumera&ccedil;&atilde;o foi definida</span></li>
    <li><span class="function"><a href="function.interface-exists.php" class="function" rel="rdfs-seeAlso">interface_exists()</a> - Verifica se a interface foi definida</span></li>
    <li><span class="function"><a href="function.get-declared-classes.php" class="function" rel="rdfs-seeAlso">get_declared_classes()</a> - Retorna um array com os nomes das classes definidas</span></li>
   </ul>
  </p>
 </div>

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