将实例化对象独立出来
abstract class ParamHandler { protected $source = ''; protected $params = array(); function __construct($source){ $this->source = $source; } function addParam($key,$value){ $this->params[$key] = $value; } function getAllParams(){ return $this->params; } static function getInstance($filename){ if($filename==1){ return new XMLParamHandler($filename); } return new TextParamHandler($filename); } abstract function write(); abstract function read(); } class XMLParamHandler extends ParamHandler{ function write(){ echo 'this is xml write'; } function read(){ echo 'this is xml read'; } } class TextParamHandler extends ParamHandler{ function write(){ echo 'this is text write'; } function read(){ echo 'this is text read'; } } $test = ParamHandler::getInstance(2); $class = new ReflectionClass('TextParamHandler'); $properties = $class->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); foreach($properties as $property) { echo $property->getName()."<br/>"; }