<?php
header("content-type:text/html;charset=utf8");
echo 'more info please go to <a>http://php.net/manual/en/class.reflectionclass.php</a>';
echo '<link>aaa</link>';
echo '<input type=button name="test" value="test">';
echo "<a>xxxx</a>";
//***************************ReflectionClass类 和 ReflectionMethod类
class Worker {
public $name='工人';
protected $age;
private $money;
public function __construct($a) {
echo '构造方法取得参数为:'.$a.'<br>';
}
public function greeting() {
echo 'Hi there, this is'.$this->name.'<br>';
}
protected function gotowork(){
echo 'Go to company to work';
}
protected function drive(){
echo 'drive to work';
}
}
class Teacher {
public $name='老师';
protected $age;
private $money;
private $height;
private $weight;
public function __construct($a, $b) {
echo '构造方法取得参数为:'.$a.$b.'<br>';
$this->a = $a;
$this->b = $b;
}
public function greeting() {
echo 'Hi there, I am a teacher from High school, and my name is'.$this->name.'<br>';
echo 'Construct args $this->a=', $this->a, ', $this->b=', $this->b.'<br>';
}
protected function gotowork(){
echo 'Go to school to work';
}
protected function drive(){
echo 'drive to school to work';
}
}
echo '类反射测试<br>获取类的属性:<br>';
$class = new ReflectionClass('teacher');
$properties = $class->getProperties();
foreach ($properties as $property) {
echo $property->getName() . "<br>";
}
echo '<br>====getEndLine====<br>';
echo $class->getEndLine();
echo '<br>====getExtensionName====<br>';
echo $class->getExtensionName();
echo '<br>====getFileName====<br>';
echo $class->getFileName();
echo '<br>====getMethods====<br>';
echo "<pre>";
print_r($class->getMethods()) ;
echo "</pre>";
echo '<br>====getModifiers====<br>';
echo $class->getModifiers();
echo '<br>========<br>';
class Instance {
function __call($className, $arguments) {
echo "<H2>调用本类没有的方法时显示此消息:</H2>";
echo "<br>返回类:==".$className;
echo "<br>返回参数==:";
if(is_array($arguments)){
var_dump($arguments);
echo "<br>";
}else{
echo $arguments;echo "<br>";
}
$class = new ReflectionClass($className);
return $class->newInstanceArgs($arguments);
}
public function callname()
{
echo "<H2>调用到了INSTANCE的方法</H2>";
}
}
$inst = new INSTANCE();
$a1='worker';
$a2='teacher';
$foo = $inst->$a2(1,2,3,4,5);
$foo = $inst->teacher(1,2,3,4,5);
$foo->greeting();
网友评论