The Reflection class

(PHP 5)


The reflection class.

Class synopsis

Reflection {
/* Methods */
public static string export ( Reflector $reflector [, bool $return = false ] )
public static array getModifierNames ( int $modifiers )

Table of Contents

add a note add a note

User Contributed Notes 1 note

apmithani at yahoo dot com
5 years ago
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:


class A
$one = '';
$two = '';
public function __construct()
//print variable one
public function echoOne()

//print variable two   
public function echoTwo()

//Instantiate the object
$a = new A();

//Instantiate the reflection object
$reflector = new ReflectionClass('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)
//Populating properties
//Invoking the method to print what was populated

To Top