码迷,mamicode.com
首页 > 其他好文 > 详细

get_class--返回对象的类名

时间:2016-02-03 18:22:12      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

get_class--返回对象的类名

string get_class ([ object $obj ] )

返回对象实例 obj 所属类的名字。如果 obj 不是一个对象则返回 FALSE

<?php 
class Person{
    public $username;
    public $age;
    public $height;
    public $weight;
    static public $number = 0;
    
    public function __construct($username,$age,$height,$weight){
        $this->username = $username;
        $this->age = $age;
        $this->height = $height;
        $this->weight = $weight;
        self::$number++;
    }
    public function __set($name,$value){
        $this->$name = $value;
    }
    
    public function __get($name){
        return $this->$name;
    }
    /**
     * 1)static方法中不能直接使用非静态成员,因为非静态成员与实例相关,通过实例化间接使用
     * 2)static方法中不能用this(与实例相关)
     * 3)非static方法中可以使用static成员
     
*/
    static public function getUsernumber(){
        var_dump(get_called_class());
        return self::$number;
    }
    
    public function getUsername(){
        var_dump(get_called_class());
        return $this->username;
    }
    
    public function __toString(){
        return ‘‘;
    }
}
$p = new Person(‘wangfei‘,36,165,52);
echo get_class($p);

?> 

get_class--返回对象的类名

标签:

原文地址:http://www.cnblogs.com/zhouguowei/p/5180299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!