PHP code example of petrp / access

1. Go to this page and download the library: Download petrp/access 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/ */

    

petrp / access example snippets


class Foo
{
	private $foo;
}

$a = Access(new Foo, '$foo');

$a->set(3);
assert($a->get() === 3);

class Foo
{
	private function bar()
	{
		return 4;
	}
}

$a = Access(new Foo, 'bar');

assert($a->call() === 4);

class Foo
{
	private $foo;

	private function bar($plus)
	{
		return $this->foo + $plus;
	}
}

$a = Access(new Foo);

$a->foo = 10;
assert($a->foo === 10);
assert($a->bar(1) === 11);

class Foo
{
	private $foo;

	public function __construct()
	{
		$this->foo = ['arrayKey' => new Bar];
	}
}
class Bar
{
	private $bar;
}

$a = AccessProxy(new Foo);

$a->foo['arrayKey']->bar = 100;
assert($a->foo['arrayKey']->bar === 100);

assert($a->foo instanceof AccessProxy);
assert(is_array($a->foo->getInstance()));
assert($a->foo['arrayKey'] instanceof AccessProxy);
assert($a->foo['arrayKey']->getInstance() instanceof Bar);