에서 메서드 호출 나는 프레임 워크 (OpenCart) 컨트롤러 클래스가 . 나는이 표현이 사용 된 것을 알고 있지만 어떻게 작동하는지 꽤 혼란 스럽다.혼란 클래스와 OpenCart
$this
현재 클래스 즉 ControllerProductProduct
지칭 그것은 $this->response
객체 ControllerProductProduct
또는 상위 클래스 Controller
하거나 존재해야 함을 의미한다. 그러나 이것은 사실이 아닙니다. 이 개체는 실제로 부모 클래스 Controller
의 보호 된 속성에 Controller::registry->data['response']->setOutput()
으로 존재합니다. 그래서 같은 말을 안 :
$this->registry->data['response']->setOutput();
대신 $ this-> 응답 ->의 setOutput를();
Controller
클래스의 스 니펫을 제공하므로 아이디어를 얻을 수 있습니다.
abstract class Controller {
protected $registry;
//Other Properties
public function __construct($registry) {
$this->registry = $registry;
}
public function __get($key) {
//get() returns registry->data[$key];
return $this->registry->get($key);
}
public function __set($key, $value) {
$this->registry->set($key, $value);
}
//Other methods
}
이 표현식이 어떻게 작동하는지 전혀 모르겠습니까? 이게 어떻게 가능할까요?
감사합니다.
나는 __get 메서드가 선언되어 있지 않고 같은 문제가 생겼다. 또한 사용할 수도있다. http : //stackoverflow.com/questions/23183327/dynamically-adding-new-properties-in- PHP – user3505400