An extended reflection class in PHP that is used to analyze PHP programs, to export or extract details about classes, methods, properties, parameters, and so on, including comments.
To see a problem like this, the member variables of the PHP class are not declared in the class, but are declared in the function, what's the difference?
Copy Code code as follows:
Class test{
Private $name;
Private $sex;
function __construct () {
$this->aaa= ' AAA ';
}
}
$test =new test ();
$reflect =new Reflectionclass ($test);
$pro = $reflect->getdefaultproperties ();
Print_r ($pro);//Print Result: Array ([name] => [sex] =>)
echo $test->aaa;//Print Result: AAA
In this test class, two member variables $name and $sex are declared, but in the constructor, a variable $aaa is declared, the class is initialized, the default member property is printed with a reflection class, and only the two member variable properties are declared, but the $AAA variable of the print class is found to be able to output the result.
The class member variable does not declare, in the function declaration is also OK, what is the difference?
In your case, it is not appropriate to use Reflectionclass because the __construct is executed only when the class is instantiated.
That is, Reflectionclass is more of a reflection class declaration structure, rather than a class-instantiated structure, so no output attribute AAA is correct, because the attribute AAA is indeed (when the class declaration) does not exist.
So how do you look at attribute AAA, the structure that should be instantiated with reflectionobject reflection, for example
Copy Code code as follows:
<?php
Class test{
Private $name;
Private $sex;
function __construct () {
$this->aaa= ' AAA ';
}
}
$test =new test ();
$reflect =new Reflectionobject ($test);
$pro = $reflect->getproperties ();
Print_r ($pro);
Once instantiated, the attribute AAA will exist, and you will be able to see the attribute AAA.
Because PHP is a "dynamic" language, it is possible to declare a member variable of a class without declaring it in a function.