PHP code example of phpactor / worse-reflection
1. Go to this page and download the library: Download phpactor/worse-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/ */
phpactor / worse-reflection example snippets
$reflector = ReflectorBuilder::create()
->addSource(' ...')
->build();
$class = $reflector->reflectClass('Foobar');
$class->methods()->get('foobar')->visiblity() == Visibility::public();
$class->properties()->get('barbar')->visiblity() == Visibility::public();
/** @var ReflectionMethod */
foreach ($class->methods() as $method) {
echo $method->name(); // methodName
echo $method->returnType()->short(); // Foobar
echo (string) $method->returnType(); // This\Is\Foobar
echo (string) $method->inferredReturnTypes()->best(); // from docblock if it exists
foreach ($method->parameters() as $parameter) {
$parameter->name(); // paramName
(string) $parameter->inferredType(); // Fully\Qualified\ParamType
}
}
foreach ($class->traits() as $trait) {
// ...
}
foreach ($class->interfaes() as $interface) {
// ...
}
foreach ($class->method('foobar')->frame()->locals() as $variable) {
$variable->offset()->toInt(); // byte offset
$variable->type(); // variable type (if available )
$variable->value(); // variable value (if available)
}
$offset = $reflection->reflectOffset(
SourceCode::fromString('...'),
Offset::fromInt(1234)
);
$offset->value()->type(); // type at offset (if available)
$offset->value()->value(); // value (e.g. 1234)
$offset->frame(); // return frame