A simple way of interrogating private methods and properties via overloading.
composer require best-served-cold/reflection
Take this class:
class ExampleClass
{
protected $protectedProperty = 1;
protected static $protectedStaticProperty = 2;
private $privateProperty = 3;
private static $privateStaticProperty = 4;
protected function protectedMethod($number)
{
return $number + 1;
}
private function privateMethod($number)
{
return $number + 2;
}
protected static function protectedStaticMethod($number)
{
return $number + 3;
}
private static function privateStaticMethod($number)
{
return $number + 4;
}
}
$reflectionClass = new ReflectionClass(ExampleClass::class);
var_dump($reflectionClass->protectedStaticProperty);
var_dump($reflectionClass->privateStaticProperty);
var_dump($reflectionClass->protectedStaticMethod(2));
var_dump($reflectionClass->privateStaticMethod(4));
Returns:
int(2)
int(4)
int(5)
int(8)
$reflectionObject = new ReflectionObject(new Exampleclass);
var_dump($reflectionObject->protectedProperty);
var_dump($reflectionObject->privateProperty);
var_dump($reflectionObject->protectedMethod(2));
var_dump($reflectionObject->privateMethod(4));
Returns:
int(1)
int(3)
int(3)
int(6)