This article mainly introduces the reflection reflection mechanism test example in PHP, from this article can learn some reflection of the use of methods, the need for friends can refer to the following
Java class reflection is applied very broadly to almost all of the core parts of the framework, and PHP programmers seem to never care about reflection. Trying to understand PHP's reflection in Java is basically consistent with Java. Refer to the PHP manual
reflecttest.php:
<?php class Reflecttest {/** * User ID */private $userId; /** * User name */private $userName; /** * User Password */private $password; /** * User Mailbox */private $email; /** * User QQ number */private $qq; /** * Number of landing times */private $loginTimes; Public Function Reflecttest () {} public Function construct ($userId, $userName, $password) {$this->userid = $userId; $this->username = $userName; $this->password = $password; }/** * * @return The $USERID * * Public Function getUserId () {return $this->userid; }/** * * @return The $userName * * Public Function GetUserName () {return $this->username; }/** * * @return The $password * * Public Function GetPassword () {return $this->password; }/** * * @return The $email * * Public Function Getemail () {return $this->email; }/** * * @return The $QQ * * Public Function getqq () {return $this->qq; }/** * * @return The $loginTimes * * Public Function Getlogintimes () {return $this->logintim Es }/** * * @param field_type $userId */Public Function Setuserid ($userId) {$this-&G T;userid = $userId; }/** * * @param field_type $userName */Public Function Setusername ($userName) {$thi S->username = $userName; }/** * * @param field_type $password */Public Function SetPassword ($password) {$thi S->password = $password; }/** * * @param field_type $email */Public Function Setemail ($email) {$this->emai L = $email; }/** * * @param field_type $QQ */Public Function setqq ($QQ) {$this->qq = $qq; }/** * * @param field_type $loginTimeS */Public Function setlogintimes ($loginTimes) {$this->logintimes = $loginTimes; }}?>
Test.php:
<?php require_once ' reflecttest.php '; $ref = new Reflecttest ("1", "admin", "admin888");//Instantiation reflecttest echo "
Request http://localhost/php/test/Test.php Output Result:
Reflecttest init. Userid:1username:adminpassword:admin888field:useridusernamepasswordemailqqlogintimesget fields DocComment:/** * User ID *//** * User name *//** * User Password *//** * User Email *//** * User QQ number *//** * Login */get Methods DocComment:/** * * @return the $user Id *//** * * @return The $userName *//** * * @return The $password *//** * * @return The $email *//** * * @return the $QQ *//** * * @return The $loginTimes *//** * * @param field_type $userId *//** * * @param field_type $userName *//** * * @par AM Field_type $password *//** * * @param field_type $email *//** * * @param field_type $qq *//** * * @param field_type $lo Gintimes */get methods:reflecttest=construct=getuserid=123getusername=rootgetpassword=123456getemail=getqq= Getlogintimes=setuserid=setusername=setpassword=setemail=setqq=setlogintimes=invoke (set/get) Qq Result: