Home  >  Article  >  Backend Development  >  php get_class() function

php get_class() function

WBOY
WBOYOriginal
2016-08-08 09:28:473064browse

<?<span>php  
  
</span><span>class</span><span> Car {  
      
    </span><span>function</span><span> getName(){  
        </span><span>echo</span> "My name is " . <span>get_class</span>() . "<br>"<span>;  
        </span><span>echo</span> "My name is " . <span>get_class</span>(<span>$this</span>) . "<br>"<span>;  
    }  
}  
  
</span><span>//</span><span>类内部调用  </span>
<span>$bar</span> = <span>new</span><span> Car();  
</span><span>$bar</span>-><span>getName();  
  
</span><span>//</span><span>类外部调用  </span>
<span>echo</span> "Its name is " . <span>get_class</span>(<span>$bar</span>) . "<br>"<span>;  
  
</span>?>   

Run results

My name is Car

My name is Car
Its name is Car

The above introduces the php get_class() function, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn