php-cs-fixer/accessible-object

A library to reveal object internals.

Installs: 532 935

Dependents: 5

Suggesters: 0

Security: 0

Stars: 11

Watchers: 6

Forks: 1

Open Issues: 0

Type:application

v1.2.0 2025-08-20 20:33 UTC

This package is auto-updated.

Last update: 2025-09-12 11:31:04 UTC


README

Accessing internals using this package makes it difficult for your IDE/SCA tools to track types properly. If you need to access internals, consider the following alternative:

$bar = \Closure::bind(static fn (Foo $object): string => $object->bar, null, Foo::class)($object);

AccessibleObject

AccessibleObject is small class allowing you to easily access internals of any object. In general, it's bad practice to do so. While we strongly discourage you to using it, it may be helpful in debugging or testing old, sad, legacy projects.

Example

<?php
class Foo
{
    private string $bar = 'baz';
}

$object = new Foo();
$bar = $object->bar; // PHP Fatal error:  Uncaught Error: Cannot access private property Foo::$bar

$accessibleObject = new AccessibleObject($object);
$bar = $accessibleObject->bar; // 'baz'