您的位置:首页 > 编程语言 > PHP开发

php 反射

2016-03-06 22:22 609 查看
//获取对象属性列表
$reflect=new ReflectionObject($student);
$props=$reflect->getProperties();
foreach($props as $prop){
print $prop->getName();
}
//获取对象方法列表
$m=$reflect->getMethods();
foreach($m as $prop){
print $prop->getName();
}

//返回对象属性关联数组
get_object_vars($student);

//类属性
get_class_vars(get_class($student));

//返回由类方法名组成的数组

get_class_methods(get_class($student));

//获取对象属性列表所属的类
get _class($student);

<?php

class mysql{
function connect($db){
echo "连接到数据库${db[0]\r\n}";
}
}
class sqlproxy{
private $target;
function _construct($tar){
$this->target[]=new $tar();
}
function _call($name,$args){
foreach ($this->target as $key => $obj) {
# code...
$r=new ReflectionClass($obj);
if($method = $r->getMethod($name)){
if($method->isPublic()&&!$method->isAbstaract()){
echo "方法拦截记录LOG\r\n";
$method->invoke($obj,$args);
echo "方法拦截\r\n";
}
}

}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: