PHPackages                             it-bens/reflection-constructor - 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. it-bens/reflection-constructor

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

it-bens/reflection-constructor
==============================

A class to find a constructor argument by an object class via Reflection API.

v0.2.0(3y ago)0222MITPHPPHP &gt;=8.0

Since Aug 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/it-bens/reflection-constructor)[ Packagist](https://packagist.org/packages/it-bens/reflection-constructor)[ RSS](/packages/it-bens-reflection-constructor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (0)

The Reflection Constructor
==========================

[](#the-reflection-constructor)

The reflection constructor (or should it be names ConstructorReflection?) can be used to find the name of parameter that matches a given type.

Why is that useful? Well, e.g. it can be used to inject data into a payload, if you only know the data (or its type), but not the name of the payload property.

How can the ReflectionConstructor be used?
------------------------------------------

[](#how-can-the-reflectionconstructor-be-used)

The ReflectionConstructor is constructed with the class name of the object it should reflect.

```
use ITB\ReflectionConstructor\ReflectionConstructor;

$constructor = new ReflectionConstructor(SomeClass::class);
```

The class provides two methods to extract the parameter name.

```
$parameterName = $constructor->extractParameterNameForClassName(SomeOtherClass::class);
// or
$someObject = new SomeOtherClass();
$parameterName = $constructor->extractParameterNameForObject($someObject)
```

What if two parameters share the same type?
-------------------------------------------

[](#what-if-two-parameters-share-the-same-type)

Let's imagine there is a class like this:

```
class SomeClass {
    public function __construct(Type1 $propertyOne, Type2 $propertyTwo, Type2 $propertyThree) {
        // ...
    }
}
```

This would work:

```
$constructor = new ReflectionConstructor(SomeClass::class);
$parameterName = $constructor->extractParameterNameForClassName(Type1::class);
// $parameterName = 'propertyOne'
```

But this would lead to an exception:

```
$constructor = new ReflectionConstructor(SomeClass::class);
$parameterName = $constructor->extractParameterNameForClassName(Type2::class);
```

The parameters 'parameterTwo' and 'parameterThree' share the same type. The resulting parameter name would be ambiguous.

That's why a list of excluded/ignored parameters can be passed to the methods. This is working again:

```
$constructor = new ReflectionConstructor(SomeClass::class);
$parameterName = $constructor->extractParameterNameForClassName(Type2::class, ['propertyTwo']);
// $parameterName = 'propertyThree'
```

Contributing
------------

[](#contributing)

I am really happy that the software developer community loves Open Source, like I do! ♥

That's why I appreciate every issue that is opened (preferably constructive) and every pull request that provides other or even better code to this package.

You are all breathtaking!

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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 ~1 days

Total

2

Last Release

1368d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/94aa1cc7aa38ca9d3f6bb96541ff813027df1f0cf478b3c53c41385876503b2c?d=identicon)[SpiGAndromeda](/maintainers/SpiGAndromeda)

---

Top Contributors

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

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/it-bens-reflection-constructor/health.svg)

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

###  Alternatives

[akamon/phunctional

λ PHP functional library

3609.4k](/packages/akamon-phunctional)[calendart/office365-adapter

Office365 Adapter for CalendArt

1213.8k](/packages/calendart-office365-adapter)

PHPackages © 2026

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