Допустим, у меня есть 3 объекта: "Место", "Человек", "Действие".
В зависимости от того, где находится человек и его возраста, этот человек может выполнять различные действия.
Например:
$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.
Как получить доступ к данным об объектах "Человек" и "Место" из класса Action?
Примеры классов:
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" от Person to Action, когда я создаю объект действия (т. Е. $ This-> action = new Action ($ this)), но как насчет данных Place?