PHP code example of best-served-cold / reflection
1. Go to this page and download the library: Download best-served-cold/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/ */
best-served-cold / reflection example snippets
class ExampleClass
{
protected $protectedProperty = 1;
protected static $protectedStaticProperty = 2;
private $privateProperty = 3;
private static $privateStaticProperty = 4;
protected function protectedMethod($number)
{
return $number + 1;
}
private function privateMethod($number)
{
return $number + 2;
}
protected static function protectedStaticMethod($number)
{
return $number + 3;
}
private static function privateStaticMethod($number)
{
return $number + 4;
}
}
$reflectionClass = new ReflectionClass(ExampleClass::class);
echo $reflectionClass->protectedStaticProperty . PHP_EOL;
echo $reflectionClass->privateStaticProperty . PHP_EOL;
echo $reflectionClass->protectedStaticMethod(2) . PHP_EOL;
echo $reflectionClass->privateStaticMethod(4) . PHP_EOL;
$reflectionObject = new ReflectionObject(new Exampleclass);
echo $reflectionObject->protectedProperty . PHP_EOL;
echo $reflectionObject->privateProperty . PHP_EOL;
echo $reflectionObject->protectedMethod(2) . PHP_EOL;
echo $reflectionObject->privateMethod(4) . PHP_EOL;