OOP返回变量

时间:2016-06-09 16:10:59

标签: php oop

你好我是OOP的新手,我有一个方法的类,我试图从一个方法返回一个变量到类,但我显然错过了一些东西......

这是我的班级:

class Certification {

    public $uid;
    public $men_id;
    public $sm_id;
    public $sm_rec;
    public $three_days;
    public $min_on_test;
    public $signed;
    public $mid_year;
    public $police_check;
    public $io_comments;
    public $date_certified;

    public function __construct($uid)
    {   
        include 'conn.php';         
        $stmt = $conn->prepare(
                               'SELECT * FROM certification WHERE uid = :uid');
        $stmt->execute(array(':uid' => $uid));

        while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
            $this->uid = $row['uid'];
            $this->nid = $row['nid'];
            $this->nid = $row['date_certified'];
            $this->men_id = $row['men_id'];
            $this->sm_id = $row['sm_id'];
            $this->sm_rec = $row['sm_rec'];
            $this->three_days = $row['three_days'];
            $this->min_on_test = $row['min_on_test'];
            $this->signed = $row['signed'];
            //$this->mid_year = $row['mid_year'];
            $this->police_check = $row['police_check'];
            $this->io_comments = $row['io_comments'];
        }
    }

    public function get_mid_year ($uid) {
        include 'conn.php'; 
        $stmt = $conn->prepare(
                               'SELECT courseReviewed FROM vti_users WHERE uid = :uid');
        $stmt->execute(array(':uid' => $uid));

        while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
            $this->mid_year = $row['courseReviewed'];
            return $this->mid_year;     
        }
    }
} 

我认为此方法会将$mid_year变量返回给类,但在使用var_dump()时为null。

任何关于纠正我的错误逻辑的建议对初学者都是一个很大的帮助。

0 个答案:

没有答案