获取类变量的函数


get function of a class variable

connect是一个类变量,它也是一个连接到数据库的对象。我怎样才能得到这个变量的函数?在Java中应该是这样的。variable.method();

public function userLoginCh($username, $password, $userId, $address, $birthday)
{
    $mdPass = md5($password);
    $addRequestString = "INSERT INTO partnerRequest (userId, address, password, birthday) VALUES (:userId, :address, :mdPass, :birthday)";
    $addRequestQuery = $this->connect->prepare($addRequestString);
    $addRequestQuery->bindParam(':userId', $userId);
    $addRequestQuery->bindParam(':address', $address);
    $addRequestQuery->bindParam(':mdPass', $mdPass);
    $addRequestQuery->bindParam(':birthday', $birthday);
}

Easy:

$this->variable->function();

好的,让我们添加一个例子:

class A {
    function say_hi() {
        echo 'Hi!';
    }
}
class B {
    private $class_a;
    function __construct() {
        $this->class_a = new A;
    }
    function say_what_a_says() {
        $this->class_a->say_hi();
    }
}
$b = new B;
$b->say_what_a_says(); // prints out: Hi!