PHP code example of piotrpress / accessor

1. Go to this page and download the library: Download piotrpress/accessor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

piotrpress / accessor example snippets


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; }
}



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';