PHPackages                             demmonico/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. demmonico/reflection

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

demmonico/reflection
====================

Helpers and traits for work with class reflections

v2.0.2(7y ago)030MITPHPPHP ~7.0

Since Aug 22Pushed 7y ago1 watchersCompare

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

READMEChangelog (3)DependenciesVersions (11)Used By (0)

Reflection
==========

[](#reflection)

Description
-----------

[](#description)

Helpers and traits for work with class reflections

[![Latest Stable Version](https://camo.githubusercontent.com/677dd65ae4e2db00c21a17b2e09754b60a7be4e54a2b50755b4a00c1e02d02a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64656d6d6f6e69636f2f7265666c656374696f6e2e737667)](https://packagist.org/packages/demmonico/reflection)[![Total Downloads](https://camo.githubusercontent.com/66ebb7c8fc980507989489ba654a9a825d7a0d244c270c0a979f91f92b454433/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64656d6d6f6e69636f2f7265666c656374696f6e2e737667)](https://packagist.org/packages/demmonico/reflection)[![License](https://camo.githubusercontent.com/5821377c1841d001b1eeb96fc5c08499105ef29381ee8adc91a79fe7c63752b4/68747470733a2f2f706f7365722e707567782e6f72672f64656d6d6f6e69636f2f7265666c656374696f6e2f6c6963656e7365)](https://packagist.org/packages/demmonico/reflection)

Components
----------

[](#components)

### ReflectionHelper

[](#reflectionhelper)

Helper for work with class reflections. Is a base of other components

##### Usage

[](#usage)

1. Get list of class methods

```
ReflectionHelper::getMethods($className, $filter=null, $prefix=null);
```

2. Get list of class constants

```
ReflectionHelper::getConstants(string $className, ?string $prefix = ''): array
```

3. Detect type of var (array, int, string etc)

```
ReflectionHelper::detectVarType($var, $allowTypesArr=[], $default=null)
```

### ConstantTrait

[](#constanttrait)

Handle magic calls to get array of class's constant labels or single constant label by it value

##### Usage

[](#usage-1)

Sourse class

```
class Simple
{
    use ConstantTrait;

    const GROUP_TEST_ONEWORD = 1;
    const GROUP_TEST_TWO_WORDS = 2;
    const GROUP_TEST_COM_plex_LAbeL = 3;

    public function test() { return $this->constGroupTest(); }
    public function testStatic() { return static::constGroupTest(); }
    public function testSingleLabel() { return $this->constGroupTest(static::GROUP_TEST_TWO_WORDS); }

    public function testInvalidPrefix() { return $this->invalidGroupTest(); }
    public function testInvalidConstGroup() { return $this->constInvalidGroup(); }
    public function testInvalidConstValue() { return $this->constGroupTest(1000); }
}
```

Anywhere usage

```
$simple = new Simple;

//
// will return CORRECT results
//
$simple->test();
// or
$simple->testStatic();
// or
Simple::testStatic();
// returns array(3) { [1]=> string(7) "Oneword" [2]=> string(10) "Two Words" [3]=> string(16) "COM plex LAbe L" }

$simple->testSingleLabel();
// returns string(10) "Two Words"

//
// will throw an ERRORS
//
$simple->testInvalidPrefix();
// or
$simple->testInvalidConstGroup();
// if no parent::__call and/or parent::__callStatic exists then
//      throws Error "Call to undefined method Simple::invalidGroupTest()" or "testInvalidConstGroup"
// else
//      throws error from parent

$simple->testInvalidConstValue();
// throws Error "Invalid argument '1000' while calling Simple::constGroupTest(1000)"
```

So correct results (not for single call) will be like this:

```
[
    1 => "Oneword",
    2 => "Two Words",
    3 => "COM plex LAbe L",
]
```

For single label call - `Oneword`

##### Customization

[](#customization)

***Change prefix for the const getter***

Define somewhere before call const getter:

```
static::$constMagicGetterPrefix = 'get';
...
Simple::getGroupTest();
```

**Note**: attempt to override static property like below will trigger an error

```
protected static $constMagicGetterPrefix = 'get';
```

***Add/override constant label for get complex label formatting***

Sourse class

```
class Simple
{
    ...
    protected static $constMagicLabels = ['GroupTest' => [3 => 'COMP-lex-LaBEL', 0 => 'Extra label']];
    ...
// or
    ...
    protected static constMagicLabels() { return ['GroupTest' => [3 => 'COMP-lex-LaBEL', 0 => 'Extra label']]; }
    ...
}
```

Anywhere usage

```
$simple->test();
// returns array(4) { [1]=> string(7) "Oneword" [2]=> string(10) "Two Words" [3]=> string(14) "COMP-lex-LaBEL" [0]=> string(11) "Extra label" }
```

So correct results in such case will be like this:

```
[
    1 => "Oneword",
    2 => "Two Words",
    3 => "COMP-lex-LaBEL",  // was replaced
    0 => "Extra label",     // was added
]
```

**Note**: you could change name of property/method of label customization via set before calling getter

```
static::$constMagicCustomLabels = 'renamedConstMagicLabels';
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~75 days

Recently: every ~156 days

Total

10

Last Release

2879d ago

Major Versions

v1.2.1 → v2.0.02018-06-08

PHP version history (2 changes)v1.0.0PHP &gt;5.5.0

v2.0.0PHP ~7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc04250a201bcb8f1e48f8d4551e4785a02e79f66f52449e70aa2435f2cdcba5?d=identicon)[demmonico](/maintainers/demmonico)

---

Top Contributors

[![demmonico](https://avatars.githubusercontent.com/u/10497315?v=4)](https://github.com/demmonico "demmonico (12 commits)")

---

Tags

helperreflectionlibrarytraitextensioncomponentconstant

### Embed Badge

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

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

PHPackages © 2026

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