https://github.com/nark3d/reflection
Simple reflection accessor
https://github.com/nark3d/reflection
Last synced: about 2 months ago
JSON representation
Simple reflection accessor
- Host: GitHub
- URL: https://github.com/nark3d/reflection
- Owner: nark3d
- License: gpl-2.0
- Created: 2017-03-14T18:47:49.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-20T14:23:29.000Z (about 8 years ago)
- Last Synced: 2025-02-08T03:45:53.485Z (3 months ago)
- Language: PHP
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/nark3d/Reflection)
[](https://scrutinizer-ci.com/g/nark3d/Reflection/build-status/master)
[](https://scrutinizer-ci.com/g/nark3d/Reflection/?branch=master)
[](https://scrutinizer-ci.com/g/nark3d/Reflection/?branch=master)
[](https://insight.sensiolabs.com/projects/4c0863ee-8947-468c-9b7e-165704e98c5f)
[](https://packagist.org/packages/best-served-cold/reflection)
[](https://codeclimate.com/github/nark3d/Reflection)
[](https://codeclimate.com/github/nark3d/Reflection)# Reflection
A simple way of interrogating private methods and properties via overloading.
## Install
```shell
composer require best-served-cold/reflection
```## Usage
Take this class:
```php
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
```php
$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:
```shell
2
4
5
8```
### Usage as an object
```php
$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:
```shell
1
3
3
6
```