Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 866 Bytes

File metadata and controls

29 lines (22 loc) · 866 Bytes

💀 Deprecation notice

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'