저는 응용 프로그램을 작업 중이며이 딜레마에 봉착했습니다. 아래는 매우 단순화 된 버전이지만 가능한지 궁금합니다.
예:
class A{
public $test = null;
public function method1(){
$this->test = 'finished';
}
}
class B extends A{
public function getMethod1Test(){
return $this->test;
}
}
$a = new A();
$a->method1();
$b = new B();
$b->getMethod1Test(); //this currently returns NULL
수정 된 값을 클래스 B에 다시 삽입하지 않고 '완료'값을 반환하도록 어떻게 수정할 수 있습니까?
감사
이렇게 A 급을 만들면 ..
class A{
public $test = null;
public function __construct(){ // constructor
$this->test = 'finished';
}
}
나는 그것을 테스트하지 않았지만 작동해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다