array get_class_vars ( string $class_name )
返回由类的默认公有属性组成的关联数组,此数组的元素以 varname => value 的形式存在。
<?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 ‘‘;
}
}
var_dump(get_class_vars(‘Person‘));
?>