<?php namespace app; class A { public $one = ''; public $two = ''; //Constructor public function __construct() { //Constructor echo "string"; } //print variable one public function echoOne() { echo $this->one."\n"; } //print variable two public function echoTwo() { echo $this->two."\n"; } } //Instantiate the object $a = new A(); //Instantiate the reflection object $reflector = new \ReflectionClass('app\A'); //Now get all the properties from class A in to $properties array $properties = $reflector->getProperties(); $i =1; //Now go through the $properties array and populate each property foreach($properties as $property) { var_dump($property->getDeclaringClass ()); //Populating properties $a->{$property->getName()}=$i; //Invoking the method to print what was populated $a->{"echo".ucfirst($property->getName())}()."\n"; $i++; } class AA {public function __construct() {}} class B extends \app\AA {} $method = new \ReflectionMethod('\app\B', '__construct'); echo $method->class; // prints 'A'

分类: web

标签: