The
PHP reflection is used to get details about the classes, extensions, methods, functions, objects, parameters, and properties. The
Reflectionclass class obtains class-related information, such as getting properties, methods, document comments, and so on.
<?php class Person {/** * For the sake of demonstration, we ' re setting this private * * Private $_allowdyn
Amicattributes = false;
/** type=primary_autoincrement * * protected $id = 0;
/** Type=varchar length=255 NULL * * * protected $name;
/** type=text NULL */protected $biography;
Public Function GetId () {return $this->id;
The Public Function setId ($v) {$this->id = $v;
The Public Function GetName () {return $this->name;
The Public Function SetName ($v) {$this->name = $v;
The Public Function getbiography () {return $this->biography;
The Public Function setbiography ($v) {$this->biography = $v;
}///Export class Reflectionclass::export (' person ');
$r = new Reflectionclass (' person ');
Gets all Properties Print_r ($r->getproperties ()); /** * Get the specified property * reflectionproperty::is_static * reflectionproperty::is_public * reflectionproperty::is_protected * REF Lectionproperty::is_private * * PRINT_R ($r->getproperties (reflectionproperty::is_private));
Gets the annotation print_r ($r->getproperty (' id ')->getdoccomment ());
Get method Print_r ($r->getmethods ());
The Reflectionextension class is used to obtain extension-related information
$re = new Reflectionextension (' Reflection ');
Print_r ($re->getclasses ()); Extended All Class
Print_r ($re->getclassnames ());//Extend all class names
$dom = new Reflectionextension (' MySQL ');
Print_r ($dom->getconstants ())//Extended constant
Print_r ($dom->getdependencies ());//This extension relies on
Print_r ($dom-> Getfunctions ())//extension method
Print_r ($dom->getinientries ());//Extended INI Information
print_r ($dom->getname ());//Extended Name
Print_r ($dom->getversion ())//Extended version
Print_r ($dom->info ())//Extended information
print_r ($dom-> Ispersistent ());/Whether it is a persistent extension
Print_r ($dom->istemporary ());//Whether it is a temporary extension
Reflectionfunction class User Gets the information about the function
$RF = new Reflectionfunction (' Array_merge ');
foreach ($rf->getparameters () as $item) {
echo $item. Php_eol;
}
Reflectionmethod-Class user access methods related information
Class Person {public
$name;
/** * Get name of person *
/public
function GetName ()
{return
$this->name;
}
Public Function SetName ($v)
{
$this->name = $v;
}
}
$RM = new Reflectionmethod (' person ', ' getName ');
Print_r ($rm->ispublic ());
Print_r ($rm->getdoccomment ());
Reflectionobject class is used to get information about objects
Class Person {public
$name;
Public function __construct ($name)
{
$this->name = $name;
}
Public Function GetName ()
{return
$this->name;
}
Public Function SetName ($v)
{
$this->name = $v;
}
}
$a = new person (' a ');
$ro = new Reflectionobject ($a);
Print_r ($ro->getmethods ());
Reflectionparameter gets information about a function or method parameter.
Class Person {public
$name;
Public function __construct ($name)
{
$this->name = $name;
}
Public Function GetName ()
{return
$this->name;
}
Public Function SetName ($v)
{
$this->name = $v;
}
}
$p = new Reflectionparameter (Array (' person ', ' setname '), 0);
Print_r ($p->getposition ()); 0
Print_r ($p->getname ());//v
Reflectionproperty gets information about the properties of the class.
Class Person {
/** Test
/public $name;
Public function __construct ($name)
{
$this->name = $name;
}
Public Function GetName ()
{return
$this->name;
}
Public Function SetName ($v)
{
$this->name = $v;
}
}
$p = new Reflectionproperty (' person ', ' name ');
Print_r ($p->getdoccomment ());