부모 클래스에서 자식 클래스 속성을 사용하려고하는데 결과를 얻을 수 없습니다. 자식 클래스에서 생성자를 사용하고 있습니다. 어쩌면 누군가가 설명 할 수 있습니다. 어떻게해야합니까? 아래에 주석 처리 된 코드를 남겨 둘 것입니다. 감사! 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.
는 마지막 질문은 지옥 잘못 편집했다.
예, 그리고 ...? 자녀에게'$ this-> email'을 사용하십시오 ...!? – deceze
보호 또는 공용으로 정의 된 모든 구성원은 하위 클래스에서 액세스 할 수 있습니다. 비공개 멤버 만 직접 액세스 할 수 없습니다 – DarkBee
오, 이런, 내가 잘못 했어. 내가 원하는 건 자식 클래스 매개 변수를 확장하는 부모 클래스를 만드는 것입니다. –