类变量未正确返回

时间:2017-05-19 10:28:29

标签: php

class userDetails {
    private $usersEmail;
    private $firstName;
    private $lastName;

    // check if it's returned
    // echo $usersEmail.' '.$firstName.' '.$lastName;
    //setter for class properties
    public function __constructor($email,$fname,$lname) {

        $this->usersEmail = $email;
        $this->firstName = $fname;
        $this->lastName = $lname;       
    }

    //getter for class properties
    function getPropertyEmail() {
        return $this->usersEmail;
    }
    function getPropertyFName() {
        return ($this->firstName);      
    }
    function getPropertyLName() {
        return ($this->lastName);       
    }
}
$something = "something";
 //$something is actually a $_GET['id']; sent from xhrobject 
$createdUser = new userDetails($something,$something,$something);
echo $createdUser->getPropertyEmail();

2 个答案:

答案 0 :(得分:1)

请使用__construct()方法而不是__constructor()

答案 1 :(得分:0)

试试这个:

class userDetails {
    private $usersEmail;
    private $firstName;
    private $lastName;

    // check if it's returned
    // echo $usersEmail.' '.$firstName.' '.$lastName;
    //setter for class properties
    public function __construct($email,$fname,$lname) {

        $this->usersEmail = $email;
        $this->firstName = $fname;
        $this->lastName = $lname;       
    }

    //getter for class properties
    function getPropertyEmail() {
        return $this->usersEmail;
    }
    function getPropertyFName() {
        return ($this->firstName);      
    }
    function getPropertyLName() {
        return ($this->lastName);       
    }
}
$something = "something";
 //$something is actually a $_GET['id']; sent from xhrobject 
$createdUser = new userDetails($something,$something,$something);
echo $createdUser->getPropertyEmail();