class GrandClass {
public $data;
public function __construct() {
$this->someMethodInTheParentClass();
}
public function someMethodInTheParentClass() {
$this->$data = 123456;
}
}
class MyParent extends GrandClass{
public function __construct() {
parent::__construct();
}
}
class Child extends MyParent {
// public $data;
public function __construct() {
parent::__construct();
}
public function getData() {
return $this->data;
}
}
$a = new Child();
var_dump($a->getData());
PHP 알림 : 정의되지 않은 변수 : 7 행 D : \ test.php의 데이터
PHP 치명적 오류 : 7 행의 D : \ test.php에서 빈 속성에 액세스 할 수 없습니다.
$ this-> data = 123456을 사용하여 아래의 someMethodInTheParentClass 함수를 업데이트하십시오.
public function someMethodInTheParentClass() {
$this->data = 123456;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다