PHPackages                             ucscode/object-reflector - 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. ucscode/object-reflector

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

ucscode/object-reflector
========================

A reflector that provides access to class encapsulated properties or methods

v2.0.0(2mo ago)032↓100%MITPHPPHP &gt;=8.1

Since May 4Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/ucscode/ObjectReflector)[ Packagist](https://packagist.org/packages/ucscode/object-reflector)[ RSS](/packages/ucscode-object-reflector/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

ObjectReflector v2.0
====================

[](#objectreflector-v20)

**Surgical precision for PHP object manipulation.**

`ObjectReflector` is a lightweight, fluent utility designed to bypass PHP encapsulation. It provides a clean API to interact with `private` and `protected` properties or methods without the boilerplate of the native Reflection API.

**Optimized for PHP 8.1+** (No `setAccessible()` required).

🚀 Features
----------

[](#-features)

- **Fluent Interface:** Chain multiple `set()` and `call()` operations in a single line.
- **Recursive Reflection:** Use `reflect()` to dive into nested object properties instantly.
- **Modern PHP:** Built to leverage PHP 8.1+ universal reflection access.
- **Zero Boilerplate:** No more `ReflectionClass` or `ReflectionMethod` manual instantiation.

---

🛠 Installation
--------------

[](#-installation)

```
composer require ucscode/object-reflector
```

---

📖 Usage
-------

[](#-usage)

### 1. Basic Manipulation (Fluent)

[](#1-basic-manipulation-fluent)

Reach into any object and modify its state, regardless of visibility.

```
use Ucscode\ObjectReflector\ObjectReflector;

$reflector = new ObjectReflector($object);

// Assuming "id" and "passwordHash" are private or protected properties
$reflector
    ->set('id', 123)
    ->set('passwordHash', $newHash)
    ->call('updateTimestamps'); // Assuming "updateTimestamps" is a private or protected method
```

### 2. Recursive Reflection

[](#2-recursive-reflection)

If a property contains another object, you can chain reflectors to access the child's internals without creating new variables.

```
$reflector
    ->reflect('invoice') // Assuming "invoice" is a private object
    ->reflect('client') // Assuming "client" is a private object inside "invoice"
    ->set('due', '$23.00'); // will set "object.invoice.client.due = $23.00"
```

### 3. Dynamic Invocation

[](#3-dynamic-invocation)

Invoke methods using variadic arguments or arrays—perfect for hydrating objects from API payloads.

```
// Variadic
$reflector->call('logAction', 'User Update', 1);

// Array-based (useful for dynamic data)
$reflector->callArray('syncStatus', [
    'status' => 'active',
    'notified' => true
]);
```

---

🎯 Why Use This?
---------------

[](#-why-use-this)

- **Testing:** Access private state in unit tests without adding public getters.
- **Hydration:** Map database or API results to strictly encapsulated Domain Entities.
- **Legacy Support:** Manipulate objects in third-party libraries that didn't provide enough hooks.

---

⚖️ License
----------

[](#️-license)

The MIT License (MIT). Please see [License File](https://www.google.com/search?q=LICENSE) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance83

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

2

Last Release

87d ago

Major Versions

1.0.0 → v2.0.02026-02-11

PHP version history (2 changes)1.0.0PHP &gt;=7.4

v2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/65673b1b31e87471999a7614d107e7e061a38bf72191d149c66c1b943124e09c?d=identicon)[ucscode](/maintainers/ucscode)

---

Top Contributors

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

---

Tags

phpreflection classproperty access

### Embed Badge

![Health badge](/badges/ucscode-object-reflector/health.svg)

```
[![Health](https://phpackages.com/badges/ucscode-object-reflector/health.svg)](https://phpackages.com/packages/ucscode-object-reflector)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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