This library provides an access to protected/private, also static, methods/properties of an object/class.
composer require piotrpress/accessor
class Example {
private $privateProperty = 'privateProperty';
protected $protectedProperty = 'protectedProperty';
static private $staticPrivateProperty = 'staticPrivateProperty';
static protected $staticProtectedProperty = 'staticProtectedProperty';
private function privateMethod( $arg1, $arg2 ) { echo $arg1 . $arg2; }
protected function protectedMethod( $arg1, $arg2 ) { echo $arg1 . $arg2; }
static private function staticPrivateMethod( $arg1, $arg2 ) { echo $arg1 . $arg2; }
static protected function staticProtectedMethod( $arg1, $arg2 ) { echo $arg1 . $arg2; }
}
require __DIR__ . '/vendor/autoload.php';
use PiotrPress\Accessor;
$accessor = new Accessor( new Example() );
$accessor->privateMethod( 'arg1', 'arg2' );
$accessor->protectedMethod( 'arg1', 'arg2' );
$accessor = new Accessor( 'Example' );
$accessor->staticPrivateMethod( 'arg1', 'arg2' );
$accessor->staticProtectedMethod( 'arg1', 'arg2' );
$accessor = new Accessor( new Example() );
echo $accessor->privateProperty;
echo $accessor->protectedProperty;
$accessor = new Accessor( 'Example' );
echo $accessor->staticPrivateProperty;
echo $accessor->staticProtectedProperty;
$accessor = new Accessor( new Example() );
$accessor->privateProperty = 'newPrivateProperty';
$accessor->protectedProperty = 'newProtectedProperty';
$accessor = new Accessor( 'Example' );
$accessor->staticPrivateProperty = 'newStaticPrivateProperty';
$accessor->staticProtectedProperty = 'newStaticProtectedProperty';
GPL3.0