OOPs Tutorials
- What is OOPs
- Access Modifier
- Constructor
- Destructor
- Polymorphism
- Inheritence
- Method Overriding
- Abstract class
- Interface
- Traits
- This keyword
- static keyword
- Final keyword
- Class Constant
- Exception Handling
- Binding in php
- tostring in php
- Object Iteration
- Reflection
- Magic methods
- Namespaces
- CRUD Function
- OOPs CRUD
- CRUD Example
Important Links
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>”;
?>