Reflect is a simple wrapper around PHP's ReflectionClass that provides easy access to private properties and methods, supporting both instanced and static members with inheritance.
- PHP 8.0+
You can install Reflect via composer:
composer require christopheraseidl/reflect
class MyClass {
private string $private = 'private property';
private function method(): string
{
return 'private method';
}
}
$reflect = Reflect::on(new MyClass());
echo $reflect->private; // 'private property'
echo $reflect->method(); // 'private method'
class MyStaticClass {
private static string $static = 'static property';
private static function staticMethod(): string
{
return 'static method';
}
}
$reflect = Reflect::on(MyStaticClass::class);
echo $reflect->static; // 'static property'
echo $reflect->staticMethod(); // 'static method'
class ParentClass {
private string $parentProp = 'parent property';
}
class Child extends ParentClass {
private string $childProp = 'child property';
}
$reflect = Reflect::on(new Child());
echo $reflect->parentProp; // 'parent property'
echo $reflect->childProp; // 'child property'
abstract class AbstractClass {
private static string $env = 'development';
}
$reflect = Reflect::on(AbstractClass::class);
echo $reflect->env; // 'development'
composer test
The MIT License (MIT). Please see License File for more information.