PHP code example of yep / reflection

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

    

yep / reflection example snippets


php composer.phar 


class SomeClass {
	private $someProperty;

	protected function someMethod($someArgument) {
		return $someArgument;
	}

	public function getSomeProperty() {
		return $this->someProperty;
	}

	public function setSomeProperty($someProperty) {
		$this->someProperty = $someProperty;
	}
}

class SomeClass2 extends SomeClass {
}

$someClass = new SomeClass();
$reflection = \Yep\Reflection\ReflectionClass::from($class = $someClass);


$someClass = new SomeClass();

echo $reflection->invokeMethod($method = 'someMethod', $arguments = ['foo']); // 'foo'


$someClass = new SomeClass();

$reflection->setPropertyValue($property = 'someProperty', $value = 'foo');

echo $someClass->getSomeProperty(); // 'foo'


$someClass = new SomeClass();
$someClass->setSomeProperty('foo');

echo $reflection->getPropertyValue($property = 'someProperty'); // 'foo';


$someClass = new SomeClass2();
$someClass->setSomeProperty('foo');

echo $reflection->getParent()->getPropertyValue($property = 'someProperty'); // 'foo';