1. Go to this page and download the library: Download stubbles/reflect 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/ */
stubbles / reflect example snippets
$refClass = reflect('some\interesting\UserDefinedClass'); // creates instance of \ReflectionClass
$refObject = reflect($someObjectInstance); // creates instance of \ReflectionObject
$refMethod = reflect('some\interesting\UserDefinedClass', 'aMethod'); // creates instance of \ReflectionMethod
$refMethod = reflect($someObjectInstance, 'aMethod'); // same as line before
$refFunction = reflect('someFunction'); // creates instance of \ReflectionFunction
$refMethod = reflectConstructor('some\interesting\UserDefinedClass'); // same as reflect('some\interesting\UserDefinedClass', '__construct');
$refMethod = reflectConstructor($someObjectInstance); // same as reflect('some\interesting\UserDefinedClass', '__construct');
namespace my;
/**
* Class to demonstrate how to define annotations
*
* @MyAnnotation
*/
class ExampleClass
{
/**
* an example property
*
* @var string
* @AnnotationWithValues(bar='dummy', baz=42, m int $param a parameter
* @CastedAnnotation[MyAnnotation]
* @ParamAnnotation{param}(key='value')
*/
public function aMethod($param)
{
// some code here
}
}
annotationsOf('my\ExampleClass', 'aMethod'); // returns annotations of this method
annotationsOf($exampleInstance, 'aMethod'); // returns annotations of this method
annotationsOf('my\ExampleClass'); // returns annotations of this class
annotationsOf($exampleInstance); // returns annotations of this class
annotationsOf('my\examplefunction'); // returns annotations of this function
annotationsOf($reflectionParameter); // returns annotations of this parameter
annotationsOf($reflectionProperty); // returns annotations of this class property