码迷,mamicode.com
首页 > Web开发 > 详细

php反射

时间:2015-12-17 16:14:27      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

<?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()."\n";
}
$method=$reflect->getMethods(); //获取方法
foreach ($method as $key=>$value)
{
    print $value->getName()."\n";
} 

输出:

父类构造函数
子类构造函数
name age __construct sayddd say

php反射

标签:

原文地址:http://www.cnblogs.com/objectboy/p/5054247.html

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