<?php class Person{ public $name="xiaoming"; function say(){ echo "i am ".$this->name; } function run($addr){ echo "i am running at ".$addr; } } $per=new Person; //$per->say(); //利用反射實現對象調用方法 //$md=new ReflectionMethod(類名,方法名); //反射方法對象 //反射的好處:能夠得到方法的屬性(是否公開,私有的,受保護的。) $md=new ReflectionMethod("Person","say"); $md->invoke($per); //經過反射執行帶參數的方法" $mds=new ReflectionMethod("Person","run"); $mds->invokeArgs($per,array("China Hongkong"));