<?php
header("Content-type:text/html;charset=utf-8");
class family {
public $name;
public $age;
public function __construct() {
echo "父类构造函数<br>";
}
public function say() {
echo "父类" . $this->name . "今年," . $this->age;
}
}
class sun extends family {
public $name; //与父类属性同名将覆盖父类的name
public $age;
public function __construct() {
parent::__construct();
echo "子类构造函数<br>";
}
public function sayddd() {
$this->name = "ddddd";
$this->age = 222;
$this->say();
}
}
$sun = new sun();
$reflect=new ReflectionClass($sun);
//ReflectionObject 继承了ReflectionClass
$props=$reflect->getProperties(); //获取类属性
foreach ($props as $prop=>$value)
{
print $value->getName()."
";
}
$method=$reflect->getMethods(); //获取方法
foreach ($method as $key=>$value)
{
print $value->getName()."
";
}
输出:
父类构造函数
子类构造函数
name age __construct sayddd say