PHPackages                             eloquent/liberator - 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. eloquent/liberator

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

eloquent/liberator
==================

A proxy for circumventing PHP access modifier restrictions.

3.0.0(4y ago)38866.8k—7.4%3[2 issues](https://github.com/eloquent/liberator/issues)20MITPHPPHP ^7.4 || ^8

Since Aug 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/eloquent/liberator)[ Packagist](https://packagist.org/packages/eloquent/liberator)[ Docs](https://github.com/eloquent/liberator)[ RSS](/packages/eloquent-liberator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (20)

> # No longer maintained
>
> [](#no-longer-maintained)
>
> This package is no longer maintained. See [this statement](https://gist.github.com/ezzatron/713a548735febe3d76f8ca831bc895c0) for more info.

Liberator
=========

[](#liberator)

*A proxy for circumventing PHP access modifier restrictions.*

Installation and documentation
------------------------------

[](#installation-and-documentation)

- Available as [Composer](http://getcomposer.org/) package [eloquent/liberator](https://packagist.org/packages/eloquent/liberator).

What is Liberator?
------------------

[](#what-is-liberator)

*Liberator* allows access to **protected** and **private** methods and properties of objects as if they were marked **public**. It can do so for both objects and classes (i.e. static methods and properties).

*Liberator*'s primary use is as a testing tool, allowing direct access to methods that would otherwise require complicated test harnesses or mocking to test.

Usage
-----

[](#usage)

### For objects

[](#for-objects)

Take the following class:

```
class SeriousBusiness
{
    private function foo($adjective)
    {
        return 'foo is ' . $adjective;
    }

    private $bar = 'mind';
}
```

Normally there is no way to call `foo()` or access `$bar` from outside the `SeriousBusiness` class, but *Liberator* allows this to be achieved:

```
use Eloquent\Liberator\Liberator;

$object = new SeriousBusiness;
$liberator = Liberator::liberate($object);

echo $liberator->foo('not so private...'); // outputs 'foo is not so private...'
echo $liberator->bar . ' = blown';         // outputs 'mind = blown'
```

### For classes

[](#for-classes)

The same concept applies for static methods and properties:

```
class SeriousBusiness
{
    static private function baz($adjective)
    {
        return 'baz is ' . $adjective;
    }

    static private $qux = 'mind';
}
```

To access these, a *class liberator* must be used instead of an *object liberator*, but they operate in a similar manner:

```
use Eloquent\Liberator\Liberator;

$liberator = Liberator::liberateClass('SeriousBusiness');

echo $liberator->baz('not so private...'); // outputs 'baz is not so private...'
echo $liberator->qux . ' = blown';         // outputs 'mind = blown'
```

Alternatively, *Liberator* can generate a class that can be used statically:

```
use Eloquent\Liberator\Liberator;

$liberatorClass = Liberator::liberateClassStatic('SeriousBusiness');

echo $liberatorClass::baz('not so private...');      // outputs 'baz is not so private...'
echo $liberatorClass::liberator()->qux . ' = blown'; // outputs 'mind = blown'
```

Unfortunately, there is (currently) no \_\_getStatic() or \_\_setStatic() in PHP, so accessing static properties in this way is a not as elegant as it could be.

Applications for Liberator
--------------------------

[](#applications-for-liberator)

- Writing [white-box](http://en.wikipedia.org/wiki/White-box_testing) style unit tests (testing protected/private methods).
- Modifying behavior of poorly designed third-party libraries.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity67

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

Total

5

Last Release

1548d ago

Major Versions

1.1.1 → 2.0.02014-02-09

2.0.0 → 3.0.02022-02-21

PHP version history (3 changes)1.0.0PHP &gt;=5.3.0

2.0.0PHP &gt;=5.3

3.0.0PHP ^7.4 || ^8

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/100152?v=4)[Erin](/maintainers/ezzatron)[@ezzatron](https://github.com/ezzatron)

---

Top Contributors

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

---

Tags

proxyreflectionobjectaccessmodifierprivateprotected

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/eloquent-liberator/health.svg)

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

###  Alternatives

[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)[myclabs/deep-copy

Create deep copies (clones) of your objects

8.9k849.8M169](/packages/myclabs-deep-copy)[phpdocumentor/reflection-common

Common reflection classes used by phpdocumentor to reflect the code structure

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

Set trusted proxies for Laravel

7.3k174.4M559](/packages/fideloper-proxy)[symfony/var-exporter

Provides tools to export, instantiate, hydrate, clone and lazy-load PHP objects

2.1k378.1M441](/packages/symfony-var-exporter)[friendsofphp/proxy-manager-lts

Adding support for a wider range of PHP versions to ocramius/proxy-manager

1.2k139.1M104](/packages/friendsofphp-proxy-manager-lts)

PHPackages © 2026

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