龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP中的reflection反射机制测试例子

时间:2014-08-06 11:49来源:网络整理 作者:网络 点击:
分享到:
这篇文章主要介绍了PHP中的reflection反射机制测试例子,从本文可以学到一些反射的使用方法,需要的朋友可以参考下

Java类反射应用得非常广泛几乎是所有框架的最核心部分,PHP程序员似乎从不关心反射。尝试着用java的思想去理解php的反射,跟java基本上基本一致。参考了php手册:http://www.php.net/manual/zh/book.reflection.php。

ReflectTest.php:

<?php
 
class ReflectTest {
 
    /**
     * 用户ID
     */
    private $userId;
 
    /**
     * 用户名
     */
    private $userName;
 
    /**
     * 用户密码
     */
    private $password;
 
    /**
     * 用户邮箱
     */
    private $email;
 
    /**
     * 用户QQ号码
     */
    private $qq;
 
    /**
     * 登陆次数
     */
    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->loginTimes;
    }
 
    /**
     *
     * @param field_type $userId            
     */
    public function setUserId($userId) {
        $this->userId = $userId;
    }
 
    /**
     *
     * @param field_type $userName          
     */
    public function setUserName($userName) {
        $this->userName = $userName;
    }
 
    /**
     *
     * @param field_type $password          
     */
    public function setPassword($password) {
        $this->password = $password;
    }
 
    /**
     *
     * @param field_type $email         
     */
    public function setEmail($email) {
        $this->email = $email;
    }
 
    /**
     *
     * @param field_type $qq            
     */
    public function setQq($qq) {
        $this->qq = $qq;
    }
 
    /**
     *
     * @param field_type $loginTimes            
     */
    public function setLoginTimes($loginTimes) {
        $this->loginTimes = $loginTimes;
    }
}
?>
精彩图集

赞助商链接