How does the reflection reflection mechanism in PHP be tested?

Source: Internet
Author: User
Tags php class
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:

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.