<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.get-class.php',
    1 => 'get_class',
    2 => 'Retourne le nom de la classe d\'un objet',
  ),
  'up' => 
  array (
    0 => 'ref.classobj.php',
    1 => 'Fonctions Classes/Objets',
  ),
  'prev' => 
  array (
    0 => 'function.get-called-class.php',
    1 => 'get_called_class',
  ),
  'next' => 
  array (
    0 => 'function.get-class-methods.php',
    1 => 'get_class_methods',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/classobj/functions/get-class.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.get-class" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">get_class</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">get_class</span> &mdash; <span class="dc-title">Retourne le nom de la classe d&#039;un objet</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.get-class-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>get_class</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.object.php" class="type object">object</a></span> <code class="parameter">$object</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   Retourne le nom de la classe de l&#039;objet <code class="parameter">object</code>.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.get-class-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">object</code></dt>
     <dd>
      <p class="para">
       L&#039;objet testé.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <span class="simpara">
        Passer explicitement <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> dans <code class="parameter">object</code> n&#039;est
        plus autorisé à partir de PHP 7.2.0 et émet une <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
        À partir de PHP 8.0.0, une <span class="classname"><a href="class.typeerror.php" class="classname">TypeError</a></span> est émise
        quand <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> est utilisé.
       </span>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.get-class-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne le nom de la classe dont <code class="parameter">object</code>
   est une instance.
  </p>
  <p class="para">
   Si <code class="parameter">object</code> est une instance d&#039;une classe qui existe
   dans un espace de noms, le nom qualifié avec l&#039;espace de noms de cette classe est retourné.
  </p>
 </div>

 <div class="refsect1 errors" id="refsect1-function.get-class-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
   Si <span class="function"><strong>get_class()</strong></span> est appelée avec autre chose qu&#039;un objet,
   une <span class="classname"><a href="class.typeerror.php" class="classname">TypeError</a></span> est levée. Antérieur à PHP 8.0.0,
   une alerte de niveau <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> était émise.
  </p>
  <p class="para">
   Si <span class="function"><strong>get_class()</strong></span> est appelée sans argument en dehors d&#039;une
   classe, une <span class="classname"><a href="class.error.php" class="classname">Error</a></span> est levée. Antérieur à PHP 8.0.0,
   une alerte de niveau <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> était émise.
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.get-class-changelog">
  <h3 class="title">Historique</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.3.0</td>
       <td>
        Appeler <span class="function"><strong>get_class()</strong></span> sans argument déclenche désormais un avertissement
        <strong><code><a href="errorfunc.constants.php#constant.e-deprecated">E_DEPRECATED</a></code></strong> ;
        précédemment, appeler cette fonction à l&#039;intérieur d&#039;une classe renvoyait le nom de cette classe.
       </td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        Appeler cette fonction depuis l&#039;extérieur d&#039;une classe
        lève désormais une <span class="classname"><a href="class.error.php" class="classname">Error</a></span>.
        Auparavant, un <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> était généré
        et la fonction renvoyait <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
       </td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>
        Antérieur à cette version, la valeur par défaut pour
        <code class="parameter">object</code> était <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> et avait le même effet que 
        ne pas passer de valeur. Désormais <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> n&#039;est plus la valeur par défaut
        pour <code class="parameter">object</code>, et n&#039;est plus une entrée valide.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.get-class-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>get_class()</strong></span></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">foo </span><span style="color: #007700">{<br />    function </span><span style="color: #0000BB">name</span><span style="color: #007700">()<br />    {<br />        echo </span><span style="color: #DD0000">"Mon nom est " </span><span style="color: #007700">, </span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">) , </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #FF8000">// création d'un objet<br /></span><span style="color: #0000BB">$bar </span><span style="color: #007700">= new </span><span style="color: #0000BB">foo</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Appel externe<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"Son nom est " </span><span style="color: #007700">, </span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">) , </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Appel interne<br /></span><span style="color: #0000BB">$bar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Son nom est foo
Mon nom est foo</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Utilisation de <span class="function"><strong>get_class()</strong></span> dans une superclasse</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">abstract class </span><span style="color: #0000BB">bar </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">()<br />    {<br />        </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">));<br />        </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">get_class</span><span style="color: #007700">());<br />    }<br />}<br /><br />class </span><span style="color: #0000BB">foo </span><span style="color: #007700">extends </span><span style="color: #0000BB">bar </span><span style="color: #007700">{<br />}<br /><br />new </span><span style="color: #0000BB">foo</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">string(3) &quot;foo&quot;
string(3) &quot;bar&quot;</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-3">
    <p><strong>Exemple #3 Utilisation de <span class="function"><strong>get_class()</strong></span> avec des espaces de noms de classe</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">namespace </span><span style="color: #0000BB">Foo\Bar</span><span style="color: #007700">;<br /><br />class </span><span style="color: #0000BB">Baz </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">()<br />    {<br /><br />    }<br />}<br /><br /></span><span style="color: #0000BB">$baz </span><span style="color: #007700">= new </span><span style="color: #0000BB">\Foo\Bar\Baz</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$baz</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">string(11) &quot;Foo\Bar\Baz&quot;</pre>
</div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.get-class-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.get-called-class.php" class="function" rel="rdfs-seeAlso">get_called_class()</a> - Le nom de la classe en &quot;Late Static Binding&quot;</span></li>
    <li><span class="function"><a href="function.get-parent-class.php" class="function" rel="rdfs-seeAlso">get_parent_class()</a> - Retourne le nom de la classe parente d'un objet</span></li>
    <li><span class="function"><a href="function.gettype.php" class="function" rel="rdfs-seeAlso">gettype()</a> - Retourne le type de la variable</span></li>
    <li><span class="function"><a href="function.get-debug-type.php" class="function" rel="rdfs-seeAlso">get_debug_type()</a> - Renvoie le nom du type de la variable d'une mani&egrave;re adapt&eacute;e au d&eacute;bogage</span></li>
    <li><span class="function"><a href="function.is-subclass-of.php" class="function" rel="rdfs-seeAlso">is_subclass_of()</a> - D&eacute;termine si un objet est une sous-classe d'une classe donn&eacute;e ou l'impl&eacute;mente</span></li>
   </ul>
  </p>
 </div>

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