Private Access ############## |Packagist| |GitLab| |GitHub| |Bitbucket| |Gitea| A small simple library to access private properties of the objects. Actually it's more an example of mad skillz than a useful tool. No Reflection API calls! Installation ============ Use composer: .. code-block:: bash composer require arokettu/private-access --dev Why ``--dev``? -------------- This library may be used for debugging or with PHP consoles like PsySH. If you are actually using it in some live system, you're doing something terribly wrong. Functions ========= These four simple functions can come in handy as helpers for something like PsySH_ .. note:: All functions also work with protected and public visibilities Class examples: .. code-block:: php A::secret value get_private_field(A::class, 'staticSecret'); // get A::$staticSecret value get_private_field([$a, B::class], 'secret'); // get $a->B::$secret value ``set_private_field`` --------------------- Set value of a private field .. code-block:: php A::secret value set_private_field(A::class, 'staticSecret', 'new secret'); // set new A::$staticSecret value set_private_field([$a, B::class], 'secret', 'new secret'); // set new $a->B::$secret value ``call_private_method`` ----------------------- Call private method .. code-block:: php A::doStuff('whatever') call_private_method(A::class, 'doStaticStuff', 'whatever'); // call A::doStaticStuff('whatever') call_private_method([$a, B::class], 'doStuff', 'whatever'); // call $a->B::doStuff('whatever') ``get_private_const`` --------------------- Get value of a private constant .. note:: This function works in all supported PHP versions but is useful only with PHP 7.1+ where constants can be private or protected .. code-block:: php