PHPackages                             bermudaphp/reflection-type-matcher - 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. bermudaphp/reflection-type-matcher

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

bermudaphp/reflection-type-matcher
==================================

v1.1(1y ago)3482MITPHPPHP ^8.1

Since Mar 10Pushed 1y ago1 watchersCompare

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

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

TypeMatcher
===========

[](#typematcher)

**TypeMatcher** is a robust PHP class for dynamic type validation using the Reflection API. It helps you determine whether a given variable conforms to a specified reflected type, supporting named types, union types, and intersection types. The class is designed for PHP 8 and later, taking advantage of modern language features like match expressions and strict type comparisons.

Features
--------

[](#features)

- **Named Type Matching**: Checks if a variable is an instance of a specified class or a built-in type.
- **Union Type Matching**: Validates the variable against multiple possible types, ensuring it matches at least one.
- **Intersection Type Matching**: Ensures the variable conforms to every type in a given intersection.
- **Strict Comparison Option**: Use strict checks for numeric and string types or allow flexible comparisons when needed.
- **Lightweight &amp; Standalone**: Easily integrate this class into your projects without the overhead of a larger framework.

Install
=======

[](#install)

```
composer require bermudaphp/reflection-type-matcher
```

Usage
=====

[](#usage)

```
    $reflector = new ReflectionFunction(static fn(int $a, int $b) => $a + $b);
    $param = $reflector->getParameters()[0];

    TypeMatcher::match($param->getType(), '22'); // true
    TypeMatcher::match($param->getType(), 22); // true
    TypeMatcher::match($param->getType(), '22', true); // false

    $reflector = new ReflectionFunction(static fn(A&B $arg) => $arg);
    $param = $reflector->getParameters()[0];

    TypeMatcher::match($param->getType(), new class implements A, B {}) // true
    TypeMatcher::match($param->getType(), new StdClass) // false

```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance48

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

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

Total

3

Last Release

384d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

php81reflectionreflection-apitype-checking

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bermudaphp-reflection-type-matcher/health.svg)

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

###  Alternatives

[w3c/website-templates-bundle

W3C Website Templates

785.7k](/packages/w3c-website-templates-bundle)

PHPackages © 2026

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