我想在父類中使用子類屬性,但我無法得到結果。我在子類中使用構造函數。也許有人可以解釋,我怎麼能做到這一點?我會在下面留下一些評論代碼。謝謝!PHP OOP強制子類看父類屬性
Class DataBase extends Main {
public $email, $password1, $password2;
function __construct($email,$password1,$password2) { //this is my child class with properties
$this->email = mysql_real_escape_string($email);
$this->password1 = mysql_real_escape_string($password1);
$this->password2 = mysql_real_escape_string($password2);
}
}
Class Main{} //this is my parent class. I want to use DataBase class properties here.
EDITED最後一個問題是地獄錯誤的。
是的,...?只需在你的孩子中使用'$ this-> email'!! – deceze 2014-12-07 13:12:53
每個被定義爲受保護或公共的成員都可以在子類中訪問。只有私人成員不能直接訪問 – DarkBee 2014-12-07 13:15:57
O gosh,我做錯了。我想要的只是讓父類擴展子類參數; x。 – 2014-12-07 13:37:11