Skip to content

Commit 7bfe2d3

Browse files
authored
Deprecation notice
1 parent 5f77857 commit 7bfe2d3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 💀 Deprecation notice
2+
3+
Accessing internals using this package makes it difficult for your IDE/SCA tools to track types properly.
4+
If you need to access internals, consider the following alternative:
5+
```php
6+
$bar = \Closure::bind(static fn ($object): string => $object->bar, null, Foo::class)($object);
7+
```
8+
19
# AccessibleObject
210

311
`AccessibleObject` is small class allowing you to easily access internals of any object.
@@ -10,12 +18,12 @@ While we strongly discourage you to using it, it may be helpful in debugging or
1018
<?php
1119
class Foo
1220
{
13-
private $bar = 'baz';
21+
private string $bar = 'baz';
1422
}
1523

1624
$object = new Foo();
17-
echo $object->bar; // PHP Fatal error: Uncaught Error: Cannot access private property Foo::$bar
25+
$bar = $object->bar; // PHP Fatal error: Uncaught Error: Cannot access private property Foo::$bar
1826

1927
$accessibleObject = new AccessibleObject($object);
20-
echo $accessibleObject->bar; // 'baz'
28+
$bar = $accessibleObject->bar; // 'baz'
2129
```

0 commit comments

Comments
 (0)