0
"Place", "Person", "Action"의 오브젝트가 있다고 가정 해 봅시다.오브젝트 구성에서 데이터 가져 오기
사람이있는 장소와이 사람의 나이에 따라이 사람은 다른 행동을 취할 수 있습니다. 예를 들어
:
$place->person->action->drive(); // OK if place is "parking" and "person" is 18+
$place->person->action->learn(); // OK if the place is "school" and person is less than 18.
어떻게 동작 클래스의 객체 "사람"과 "장소"에 대한 데이터를 액세스 할 수 있습니까?
클래스 예 :
class Place {
public $person;
private $name;
function __construct($place, $person) {
$this->name = $place;
$this->person = $person;
}
}
class Person {
public $action;
private $name;
private $age;
function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
$this->action = new Action();
}
}
class Action {
public function drive() {
// How can I access the person's Age ?
// How can I acess the place Name ?
}
public function learn() {
// ... Same problem.
}
}
은 내가 전송할 수있을 것 "$이"사람의 행동에 내가 작업 개체를 생성 (. 즉, $ this-> 조치를 = 새로운 액션 ($이)) 하지만 장소 데이터는 어떻게됩니까?