What is Reflection?

Using relection in OOP means that you can examine your own code at run time.
To get information about this method, you can use the ReflectionFunction class.

<?php
function tracker( )
{
static $counter = 10;
$counter++;
return $counter;
}
$method = new ReflectionFunction(‘tracker’);


?>

Now you can use this new object, $method , to find the name of the method it represents, the lines the method spans in code, what happens when you pass data to the method, what static properties the method has, and more.

<?php
function tracker( )
{
static $counter = 10;
$counter++;
return $counter;
}
$method = new ReflectionFunction(‘tracker’);
echo “the method named ”, $method->getName( );
if($method -> getStaticVariables( ))
{
$sta = $method->getStaticVariables( );
echo “it has the static variable : “, var_export($sta, 1), “<br>”;
}

Echo “invoking the method results in “, var_dump($method->invoke()), “<br>”;


?>





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here