Sophie

Sophie

distrib > Mageia > 7 > armv7hl > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 3712

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the name of the class of an object</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-class-vars.html">get_class_vars</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.get-declared-classes.html">get_declared_classes</a></div>
 <div class="up"><a href="ref.classobj.html">Classes/Object Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><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)</p><p class="refpurpose"><span class="refname">get_class</span> &mdash; <span class="dc-title">Returns the name of the class of an object</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="type">string</span> <span class="methodname"><strong>get_class</strong></span>
    ([ <span class="methodparam"><span class="type">object</span> <code class="parameter">$object</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Gets the name of the class of the given <code class="parameter">object</code>.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.get-class-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">object</code></dt>

     <dd>

      <p class="para">
       The tested object. This parameter may be omitted when inside a class.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <span class="simpara">
        Explicitly passing <strong><code>NULL</code></strong> as the <code class="parameter">object</code> is no
        longer allowed as of PHP 7.2.0.
       </span>
       <span class="simpara">
        The parameter is still optional and calling <span class="function"><strong>get_class()</strong></span>
        without a parameter from inside a class will work, but passing <strong><code>NULL</code></strong> now
        emits an <strong><code>E_WARNING</code></strong> notice.
       </span>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.get-class-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the name of the class of which <code class="parameter">object</code> is an
   instance. Returns <strong><code>FALSE</code></strong> if <code class="parameter">object</code> is not an 
   object.
  </p>
  <p class="para">
   If <code class="parameter">object</code> is omitted when inside a class, the
   name of that class is returned.
  </p>
  <p class="para">
   If the <code class="parameter">object</code> is an instance of a class which exists 
   in a namespace, the qualified namespaced name of that class is returned.
  </p>
 </div>

 <div class="refsect1 errors" id="refsect1-function.get-class-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   If <span class="function"><strong>get_class()</strong></span> is called with anything other than an
   object, an <strong><code>E_WARNING</code></strong> level error is raised.
  </p>
 </div>

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

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.2.0</td>
       <td>
        <strong><code>NULL</code></strong> was removed as the default value for <code class="parameter">object</code>,
        and is no longer a valid input.
       </td>
      </tr>

      <tr>
       <td>5.3.0</td>
       <td>
        <strong><code>NULL</code></strong> became the default value for <code class="parameter">object</code>,
        so passing <strong><code>NULL</code></strong> to <code class="parameter">object</code> now has the same
        result as not passing any value.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.get-class-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="function.usort.examples.basic">
    <p><strong>Example #1 Using <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&nbsp;</span><span style="color: #0000BB">foo&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">name</span><span style="color: #007700">()<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"My&nbsp;name&nbsp;is&nbsp;"&nbsp;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">)&nbsp;,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;create&nbsp;an&nbsp;object<br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;external&nbsp;call<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Its&nbsp;name&nbsp;is&nbsp;"&nbsp;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">)&nbsp;,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;internal&nbsp;call<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>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Its name is foo
My name is foo
</pre></div>
    </div>
   </div>
   <div class="example" id="function.usort.examples.multi">
    <p><strong>Example #2 Using <span class="function"><strong>get_class()</strong></span> in superclass</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&nbsp;class&nbsp;</span><span style="color: #0000BB">bar&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__construct</span><span style="color: #007700">()<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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 />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />class&nbsp;</span><span style="color: #0000BB">foo&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">bar&nbsp;</span><span style="color: #007700">{<br />}<br /><br />new&nbsp;</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>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(3) &quot;foo&quot;
string(3) &quot;bar&quot;
</pre></div>
    </div>
   </div>
   <div class="example" id="function.usort.examples.object">
    <p><strong>Example #3 Using <span class="function"><strong>get_class()</strong></span> with namespaced classes</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&nbsp;</span><span style="color: #0000BB">Foo</span><span style="color: #007700">\</span><span style="color: #0000BB">Bar</span><span style="color: #007700">;<br /><br />class&nbsp;</span><span style="color: #0000BB">Baz&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__construct</span><span style="color: #007700">()<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$baz&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">Foo</span><span style="color: #007700">\</span><span style="color: #0000BB">Bar</span><span style="color: #007700">\</span><span style="color: #0000BB">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>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
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">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.get-called-class.html" class="function" rel="rdfs-seeAlso">get_called_class()</a> - The &quot;Late Static Binding&quot; class name</span></li>
    <li class="member"><span class="function"><a href="function.get-parent-class.html" class="function" rel="rdfs-seeAlso">get_parent_class()</a> - Retrieves the parent class name for object or class</span></li>
    <li class="member"><span class="function"><a href="function.gettype.html" class="function" rel="rdfs-seeAlso">gettype()</a> - Get the type of a variable</span></li>
    <li class="member"><span class="function"><a href="function.is-subclass-of.html" class="function" rel="rdfs-seeAlso">is_subclass_of()</a> - Checks if the object has this class as one of its parents or implements it</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-class-vars.html">get_class_vars</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.get-declared-classes.html">get_declared_classes</a></div>
 <div class="up"><a href="ref.classobj.html">Classes/Object Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>