PHPackages                             raphhh/trex-reflection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. raphhh/trex-reflection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

raphhh/trex-reflection
======================

Reflection helpers for callables and types

1.1.0(5y ago)14324.0k—1.4%310MITPHPPHP &gt;=5.4

Since Jan 20Pushed 5y ago3 watchersCompare

[ Source](https://github.com/Raphhh/trex-reflection)[ Packagist](https://packagist.org/packages/raphhh/trex-reflection)[ Docs](https://github.com/Raphhh/trex-reflection)[ RSS](/packages/raphhh-trex-reflection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (10)Used By (10)

TRex Reflection
===============

[](#trex-reflection)

[![Latest Stable Version](https://camo.githubusercontent.com/feb29c28f632d3eba4634d7ff2ee301091efe8b54d8958c4580d0bff8bff4850/68747470733a2f2f706f7365722e707567782e6f72672f7261706868682f747265782d7265666c656374696f6e2f762f737461626c652e737667)](https://packagist.org/packages/raphhh/trex-reflection)[![Build Status](https://camo.githubusercontent.com/ed673982348173aaed184fa0ffcb9eca0057811e47a60d052527716f56aaca8c/68747470733a2f2f7472617669732d63692e6f72672f5261706868682f747265782d7265666c656374696f6e2e706e67)](https://travis-ci.org/Raphhh/trex-reflection)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/cfd899b7961c8a95f0fd97b80ee5ba19150fa5a3980d8163412016946fa32b5b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5261706868682f747265782d7265666c656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Raphhh/trex-reflection/)[![Code Coverage](https://camo.githubusercontent.com/47955fd9cb8c169d7615c18cc333242e0c65204d1fa61894656a82d22dd51e5d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5261706868682f747265782d7265666c656374696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Raphhh/trex-reflection/)[![Dependency Status](https://camo.githubusercontent.com/cba357333b0432349fe43a550cee5d02a38f8c3e8615712fcf4364e810e8e0ef/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3534303632656239633463313837666636313030303036662f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/54062eb9c4c187ff6100006f)[![Total Downloads](https://camo.githubusercontent.com/a746d5336f61db93c6b5e0fbe49fdbe17ea84f37f4e0018c926e44fe6849718e/68747470733a2f2f706f7365722e707567782e6f72672f7261706868682f747265782d7265666c656374696f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/raphhh/trex-reflection)[![Reference Status](https://camo.githubusercontent.com/9b4ca26fe39e33cbd1280a5479cae5f4970366232f950d641a8531d75c091503/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f7261706868683a747265782d7265666c656374696f6e2f7265666572656e63655f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/php/raphhh:trex-reflection/references)[![License](https://camo.githubusercontent.com/17f17998e5ced5d9e5247cc9ba13023ed0b05ce41b173e9610f5b3adac799b94/68747470733a2f2f706f7365722e707567782e6f72672f7261706868682f747265782d7265666c656374696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/raphhh/trex-reflection)

PHP tool to reflect callables an types.

Installation
------------

[](#installation)

Use composer command:

```
$ composer require raphhh/trex-reflection

```

Documentation
-------------

[](#documentation)

- [CallableReflection](#callablereflection)
- [TypeReflection](#typereflection)

### CallableReflection

[](#callablereflection)

You can use CallableReflection to inspect and call a callable, like a callback or a Closure for example.

#### All kind of callable

[](#all-kind-of-callable)

You can know which kind of callable is given.

##### Closure

[](#closure)

```
$reflect = new CallableReflection(function(){});
$reflect->isClosure(); //true
```

##### Function

[](#function)

```
$reflect = CallableReflection('in_array')
$reflect->isFunction(); //true
```

##### Static method

[](#static-method)

```
$reflect = new CallableReflection('\DateTime::createFromFormat');
$reflect->isMethod(); //true
$reflect->isStaticMethod(); //true
```

```
$reflect = new CallableReflection(array('\DateTime', 'createFromFormat'));
$reflect->isMethod(); //true
$reflect->isStaticMethod(); //true
```

##### Instance method

[](#instance-method)

```
$reflect = new CallableReflection(array(new \DateTime(), 'modify'));
$reflect->isMethod(); //true
$reflect->isInstanceMethod(); //true
```

##### Invoked object

[](#invoked-object)

```
class Bar{
    function __invoke(){}
}

$reflect = new CallableReflection(new Bar());
$reflect->isInvokedObject(); //true
```

#### Retrieve contexts

[](#retrieve-contexts)

You can retrieve the callable, like the object or the method name for example.

##### Closure

[](#closure-1)

```
$reflect = new CallableReflection(function(){});
$reflect->getClosure(); //closure
```

##### Function

[](#function-1)

```
$reflect = new CallableReflection('in_array')
$reflect->getFunctionName(); //'in_array'
```

##### Static method

[](#static-method-1)

```
$reflect = new CallableReflection('\DateTime::createFromFormat');
$reflect->getClassName(); //'DateTime'
$reflect->getMethodName(); //'createFromFormat'
```

```
$reflect = new CallableReflection(array('\DateTime', 'createFromFormat'));
$reflect->getClassName(); //'DateTime'
$reflect->getMethodName(); //'createFromFormat'
```

##### Instance method

[](#instance-method-1)

```
$reflect = new CallableReflection(array(new \DateTime(), 'modify'));
$reflect->getClassName(); //'DateTime'
$reflect->getObject(); //DateTime instance
$reflect->getMethodName(); //'modify'
```

##### Invoked object

[](#invoked-object-1)

```
class Bar{
    function __invoke(){}
}

$reflect = new CallableReflection(new Bar());
$reflect->getClassName(); //'Bar'
$reflect->getObject(); //Bar instance
```

#### Invoke callable

[](#invoke-callable)

You can invoke every kind of callable in a same way.

#### With a list of args

[](#with-a-list-of-args)

This method calls the method and give to it all its args.

```
$reflect = new CallableReflection('in_array')
$reflect->invoke(1, [0, 1]); //true
```

#### With an array of args

[](#with-an-array-of-args)

This method allows to map each value of an array with every params of a function. Useful to use dynamic args with func\_get\_args().

```
$reflect = new CallableReflection('in_array')
$reflect->invoke([1, [0, 1]]); //true
```

#### With a map of args

[](#with-a-map-of-args)

This method allows to map the keys of an array with the name of the params of a function. So, the order of the args has no importance.

```
$closure = function($arg1, $arg2){
    return [$arg1, $arg2];
}

$reflect = new CallableReflection($closure)
$reflect->invokeA(['arg2' => 'arg2', 'arg1' => 'arg1'])); //['arg1', 'arg2']
```

#### Retrieve the associated reflection class

[](#retrieve-the-associated-reflection-class)

Retrieve the [ReflectionFunctionAbstract](http://php.net/manual/en/class.reflectionfunction.php) of the callable.

##### For a function or a closure

[](#for-a-function-or-a-closure)

```
$reflect = new CallableReflection('in_array');
$reflect->getReflector(); //ReflectionFunction
```

##### For a method

[](#for-a-method)

```
$reflect = new CallableReflection(array('\DateTime', 'createFromFormat'));
$reflect->getReflector(); //ReflectionMethod
```

##### For a class

[](#for-a-class)

Note that for a class, we get a `ReflectionMethod` for the `__invoke` method of the current object, and not a `ReflectionClass`.

```
class Bar{
    function __invoke(){}
}

$reflect = new CallableReflection(new Bar());
$reflect->getReflector(); //ReflectionMethod
```

### TypeReflection

[](#typereflection)

Reflection on the type of a variable or function.

#### What is a type?

[](#what-is-a-type)

A type is a string defined by a specific value related to one of the [PHP types](http://php.net/manual/en/language.types.php).

```
$typeReflection = new TypeReflection('int');
$typeReflection->getType(); //"int"
$typeReflection->getStandardizedType(); //"integer"
```

If you work with a variable, you can use `TypeReflection::createFromVariable($variable)`

```
$foo = new stdClass();
$typeReflection = TypeReflection::createFromVariable($foo);
$typeReflection->getType(); //"stdClass"
$typeReflection->getStandardizedType(); //"object"
```

Note the `TypeReflection` is case insensitive.

#### Standardized types

[](#standardized-types)

`TypeReflection` standardizes types with following values:

- `void`
- `mixed`
- `null`
- `boolean`
- `string`
- `integer`
- `float`
- `number`
- `scalar`
- `array`
- `object`
- `resource`
- `callable`
- `unknown type`

#### Valid any type

[](#valid-any-type)

##### Recognition

[](#recognition)

```
$typeReflection = new TypeReflection('string');
$typeReflection->isValid(); //true
```

```
$typeReflection = new TypeReflection('foo');
$typeReflection->isValid(); //false
```

##### boolean

[](#boolean)

```
$typeReflection = new TypeReflection('bool');
$typeReflection->isBoolean(); //true
```

```
$typeReflection = new TypeReflection('boolean');
$typeReflection->isBoolean(); //true
```

##### string

[](#string)

```
$typeReflection = new TypeReflection('string');
$typeReflection->isString(); //true
```

##### integer

[](#integer)

```
$typeReflection = new TypeReflection('int');
$typeReflection->isInteger(); //true
```

```
$typeReflection = new TypeReflection('integer');
$typeReflection->isInteger(); //true
```

```
$typeReflection = new TypeReflection('long');
$typeReflection->isInteger(); //true
```

##### float

[](#float)

```
$typeReflection = new TypeReflection('float');
$typeReflection->isFloat(); //true
```

```
$typeReflection = new TypeReflection('double');
$typeReflection->isFloat(); //true
```

```
$typeReflection = new TypeReflection('real');
$typeReflection->isFloat(); //true
```

##### number

[](#number)

Any integer or float value.

##### scalar

[](#scalar)

Any boolean, string or number value.

##### array

[](#array)

```
$typeReflection = new TypeReflection('array');
$typeReflection->isArray(); //true
```

```
$typeReflection = new TypeReflection('int[]');
$typeReflection->isArray(); //true
```

##### object

[](#object)

```
$typeReflection = new TypeReflection('object');
$typeReflection->isObject(); //true
```

```
$typeReflection = new TypeReflection('Datetime');
$typeReflection->isObject(); //true
```

##### resource

[](#resource)

```
$typeReflection = new TypeReflection('resource');
$typeReflection->isResource(); //true
```

##### callable

[](#callable)

```
$typeReflection = new TypeReflection('callable');
$typeReflection->isCallable(); //true
```

##### void

[](#void)

```
$typeReflection = new TypeReflection('void');
$typeReflection->isVoid(); //true
```

##### null

[](#null)

```
$typeReflection = new TypeReflection('null');
$typeReflection->isNull(); //true
```

##### mixed

[](#mixed)

```
$typeReflection = new TypeReflection('mixed');
$typeReflection->isMixed(); //true
```

#### Retrieve a standard notation

[](#retrieve-a-standard-notation)

```
$typeReflection = new TypeReflection('bool');
$typeReflection->getStandardizedType(); //boolean
```

```
$typeReflection = new TypeReflection('int');
$typeReflection->getStandardizedType(); //integer
```

```
$typeReflection = new TypeReflection('real');
$typeReflection->getStandardizedType(); //float
```

```
$typeReflection = new TypeReflection('int[]');
$typeReflection->getStandardizedType(); //array
```

```
$typeReflection = new TypeReflection('Datetime');
$typeReflection->getStandardizedType(); //object
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 90.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~248 days

Recently: every ~410 days

Total

9

Last Release

2153d ago

Major Versions

0.2.3 → 1.0.02016-08-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/5fd55d984cf31c25f875f5636331a20f8be77e9443f2fd17fbccf1f9c4fe7a4c?d=identicon)[raphhh](/maintainers/raphhh)

---

Top Contributors

[![Raphhh](https://avatars.githubusercontent.com/u/5206490?v=4)](https://github.com/Raphhh "Raphhh (19 commits)")[![mwijngaard](https://avatars.githubusercontent.com/u/273701?v=4)](https://github.com/mwijngaard "mwijngaard (1 commits)")[![perk11](https://avatars.githubusercontent.com/u/1924829?v=4)](https://github.com/perk11 "perk11 (1 commits)")

---

Tags

typecallablereflection

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/raphhh-trex-reflection/health.svg)

```
[![Health](https://phpackages.com/badges/raphhh-trex-reflection/health.svg)](https://phpackages.com/packages/raphhh-trex-reflection)
```

###  Alternatives

[phpdocumentor/reflection-common

Common reflection classes used by phpdocumentor to reflect the code structure

9.1k706.8M26](/packages/phpdocumentor-reflection-common)[phpoption/phpoption

Option Type for PHP

2.7k541.2M159](/packages/phpoption-phpoption)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[jetbrains/phpstorm-stubs

PHP runtime &amp; extensions header files for PhpStorm

1.4k27.7M68](/packages/jetbrains-phpstorm-stubs)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49644.8M97](/packages/marc-mabe-php-enum)[php-di/invoker

Generic and extensible callable invoker

26857.8M56](/packages/php-di-invoker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
