Skip to content
Simple reflection accessor
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
src
tests
.codeclimate.yml
.gitattributes
.php_cs
.scrutinizer.yml
.travis.yml
LICENSE
README.md
composer.json
composer.lock
phpdoc.xml
phpunit.xml

README.md

Build Status Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight Latest Stable Version Code Climate Issue Count

Reflection

A simple way of interrogating private methods and properties via overloading.

Install

composer require best-served-cold/reflection

Usage

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;
    }
}

Usage as a class

$reflectionClass = new ReflectionClass(ExampleClass::class);

echo $reflectionClass->protectedStaticProperty . PHP_EOL;
echo $reflectionClass->privateStaticProperty . PHP_EOL;
echo $reflectionClass->protectedStaticMethod(2) . PHP_EOL;
echo $reflectionClass->privateStaticMethod(4) . PHP_EOL;

Returns:

2
4
5
8

Usage as an object

$reflectionObject = new ReflectionObject(new Exampleclass);

echo $reflectionObject->protectedProperty . PHP_EOL;
echo $reflectionObject->privateProperty . PHP_EOL;
echo $reflectionObject->protectedMethod(2) . PHP_EOL;
echo $reflectionObject->privateMethod(4) . PHP_EOL;

Returns:

1
3
3
6
You can’t perform that action at this time.