I am trying to build some classes for a project and I was wondering how to achieve the following. I am not really sure how to ask this with words but I will provide an example:
class Table{
private $name;
private $fields = [];
public function addField(Field $field){
$this->fields[$field->getName()] = $field;
}
public function getName(){
return $this->name;
}
}
class Field{
private $name;
public function getName(){
return $this->name;
}
public function getTableName(){
//return Table::getName
}
public function getTable(){
//return a ref to the Table object
}
}
$table = new Table();
$field = new Field();
$table->addField($field);
What I am trying to achieve here, once the $field is added to the $table, is there some sort of way to get the reference of the $table from any of the methods in the $field object
I would greatly appreciate any help or ideas how to restructure it so I can achieve my goal
Thank you in advance