Reflection Reflection Mechanism Test Example _php example in PHP

Source: Internet
Author: User
Tags reflection

Java class reflection is widely used and is almost the core of all frameworks, and PHP programmers don't seem to care about reflection. Try to use the Java idea to understand PHP's reflection, and Java basically consistent. Refer to the PHP Manual: http://www.php.net/manual/zh/book.reflection.php.

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;       /**      * landing times      */ 
   private $loginTimes;       public function Reflecttest () {  &NBSP;&NBSP;&NBSP;&NBSP}       public function __construct ($userId, $userName, $password) {  
       $this->userid = $userId;
         $this->username = $userName;
         $this->password = $password; &NBSP;&NBSP;&NBSP;&NBSP}       /**      *       * @return The $userId      */    public function GetUserId ( {        return $this->userid;    &nbsp}        /**      *      * @return the $userName       */    public function GetUserName () {     
   return $this->username; &NBSP;&NBSP;&NBSP;&NBSP}   &NBSP;&NBSP;&Nbsp; /**      *      * @return the $password       */    public function GetPassword () {      
  return $this->password; &NBSP;&NBSP;&NBSP;&NBSP}       /**      *    
  * @return The $email      */    public function GetEmail () {
        return $this->email; &NBSP;&NBSP;&NBSP;&NBSP}       /**      *       * @return The $qq      */    public function getQq () { 
       return $this->qq; &NBSP;&NBSP;&NBSP;&NBSP}       /**      *       * @return The $logIntimes      */    public function Getlogintimes () {  
      return $this->logintimes; &NBSP;&NBSP;&NBSP;&NBSP}       /**      *       * @param field_type $userId                   */    public function Setuserid ($userId) {    
     $this->userid = $userId; &NBSP;&NBSP;&NBSP;&NBSP}       /**      *       * @param field_type $userName                 */    public function Setusername ($userName) {     
    $this->username = $userName; &NBSP;&NBSP;&NBSP;&NBSP}   &NBSP;&NBSP;&NBSP /**      *      * @param field_type $password                 */    public
function SetPassword ($password) {         $this->password = $password; &NBSP;&NBSP;&NBSP;&NBSP}       /**      *       * @param field_type $email                */    public function Setemail ($email) {       
  $this->email = $email; &NBSP;&NBSP;&NBSP;&NBSP}       /**      *       * @param field_type $qq                   */    public function Setqq ($QQ) {
         $this->qq = $qq; &NBSP;&NBSP;&NBSP;&NBSP}       /**      *     
  * @param field_type $loginTimes                  */    public function Setlogintimes ($loginTimes) {  
       $this->logintimes = $loginTimes; &NBSP;&NBSP;&NBSP;&NBSP}}?>

Test.php:

<?php require_once ' reflecttest.php '; $ref = new Reflecttest ("1", "admin", "admin888"),//instantiated reflecttest echo " 

Request http://localhost/php/test/Test.php Output results:

Reflecttest init.
 
Userid:1
username:admin
password:admin888
Field:
 
UserId
UserName
Password
Email
QQ
logintimes get
Fields doccomment:
 
/** * User ID//** * user name//** * User
Password/
/** * User mail  Box
//** * User QQ number
//** * Login times
/Get Methods doccomment:
 
/** * * @return the $USERID/
/** * @return The $userName * * * * * * * * * @return The $password * * * * * @return The $email * * * * */** */** * @return
th E $QQ * * * * * @return The $loginTimes * * * * * * @param field_type $userId * * * * * * * *
@param field_type/** * * *
/** $userName/
/** * * @param field_type $password/
/** * * @param field_type $email/
/** * * @param fiel D_type $qq
//** * * @param field_type $loginTimes
/Get Methods:
 
reflecttest=
__construct=
getuserid=123
getusername=root
getpassword=123456
getemail=
getqq=
getlogintimes=
setuserid=
setusername=
setpassword=
setemail=
setqq=
setlogintimes= Invoke (set/get) Qq result:
 
getqq:441637262
jb51.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.