PHP之get_class — 返回对象的类名

臭大佬 2017-06-01 18:50:10 1239
php 
简介 PHP之get_class — 返回对象的类名

string get_class ([ object $object = NULL ] )

返回对象实例 object 所属类的名字。

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

运行结果

My name is Car

My name is Car
Its name is Car