1. Go to this page and download the library: Download xp-framework/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/ */
foreach ($type->annotations() as $annotation) {
$annotation->type(); // Author::class
$annotation->name(); // 'author'
$annotation->arguments(); // ['Test', test => true]
$annotation->argument(0); // 'Test'
$annotation->argument('test'); // true
$annotation->newInstance(); // Author class instance
}
$type->annotation(Inject::class); // Annotation or NULL
$type->constructor(); // Constructor or NULL
if ($constructor= $type->constructor()) {
$constructor->name(); // '__construct'
$constructor->compoundName(); // 'org.example.Fixture::__construct()'
$constructor->modifiers(); // Modifiers<public>
$constructor->comment(); // (api doc comment)
$constructor->annotations(); // Annotations
$constructor->annotation(Inject::class); // Annotation or NULL
$constructor->declaredIn(); // Type
$constructor->parameters(); // Parameters
$constructor->parameter(0); // Parameter or NULL
$constructor->newInstance([]); // (instance of the type)
}
// Instantiates type without invoking a constructor
// Any passed arguments are discarded silently
$instance= $type->initializer(null)->newInstance();
// Instantiates type by providing a constructor, regardless of whether one exists or not
// Arguments are passed on to the initializer function, which has access to $this
$instance= $type->initializer(function($name) { $this->name= $name; })->newInstance(['Test']);
// Instantiates type by selecting an instance method as an initializer
// The unserialize callback is invoked with ['name' => 'Test']
if ($unserialize= $type->initializer('__unserialize')) {
$instance= $unserialize->newInstance([['name' => 'Test']]);
}