首頁  >  文章  >  後端開發  >  php get_class()函數

php get_class()函數

WBOY
WBOY原創
2016-08-08 09:28:473097瀏覽

<?<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>?>   

運行結果

My name is Car

My name is Car
Its name is Car

以上就介紹了php get_class()函數,包含了面向的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn