$name == null) { if($name == "owner") { if($this->id) { $this->owner = new Address($this->owner_id); return $this->owner; } else { return null; } } if($name == "pops") { if($this->id) { $pops = PopModel::search(['network_id' => $this->id]); $this->pops = $pops; return $this->pops; } else { return null; } } $classname = ucfirst($name); $idfield = $name."_id"; $this->$name = new $classname($this->$idfield); if($this->$name->id) { return $this->$name; } else { return null; } } return $this->$name; } }