User Contributed Notes 1 note

Here is a code snippet for some of us who are just beginning with reflection. I have a simple class below with two properties and two methods. We will use reflection classes to populate the properties dynamically and then print them:

//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 propertyforeach($properties as $property){//Populating properties$a->{$property->getName()}=$i;//Invoking the method to print what was populated$a->{"echo".ucfirst($property->getName())}()."\n";