Hi,
I have three classes MainClass, Member, and Project. Member and Project extend the MainClass.
First I create a MainClass object, then a Member object and execute the function setMember:
$mainclass = new MainClass();
$member = new Member($id);
$mainclass->setMember($member);
When the $member variable is set to the current member I want to use this variable in my Project class but I can't get it to work :s
I need the member's id so in theory there are two possibilities:
mysql_query("INSERT INTO projects (title, user_id) VALUES('$title', ".$this->member->id.")");
or
mysql_query("INSERT INTO projects (title, user_id) VALUES('$title', ".$this->member->getId().")");
The first one, $this->member->id, results NULL
The second one, $this->member->getId(), gives me this error:
Call to a member function getId() on a non-object in ....
Here are my classes (I stripped most of it offcourse)
class MainClass{
public $member = NULL;
public function __construct(){}
public function setMember($member)
{
$this->member = $member;
}
public function getMember()
{
return $this->member;
}
}
class Project extends MainClass{
public $id;
public function __construct($id=NULL){
$this->setId($id);
}
public function setId($id){
$this->id = $id;
}
public function getId(){
return $this->id;
}
public function addProject($title){
mysql_query("INSERT INTO projects (title, user_id) VALUES('$title', ".$this->member->getId().")");
}
}
class Member extends MainClass{
public $id;
public function __construct($id=NULL){
$this->setId($id);
}
public function setId($id){
$this->id = $id;
}
public function getId(){
return $this->id;
}
}