The member variables of the php class do not declare class & nbsp; test {& nbsp; private & nbsp; $ name; & nbsp; & nbsp; private & nbsp; $ sex; & nbsp php member variables are not declared
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 the result: Array ([name] => [sex] =>)
Echo $ test-> aaa; // print the result: aaa
In this test class, two member variables $ name and $ sex are declared, but in the constructor, another variable $ aaa is declared, and the class is initialized, using the reflection class to print the default member attribute only has two declared member variable attributes, but the $ aaa variable of the print class can still be output.
Do I have to declare the member variables of the class? Can I declare them in the function? what is the difference? Php object-oriented sharing:
------ Solution --------------------
Dynamically generated object attributes are global, which is the same as variables that can be accessed without being declared.
However, due to some academic criticism, php began to give up this lightweight expression method.
Therefore, try not to do this.