ibanja
asked on
How/Can I implement a class has-a class relationship?
I have been programing with PHP for a little bit. I know enough to do some basic things but I want to organize my code and get more OO based.
I am trying to make a class that has classes. Is that possible and if so, what am I doing wrong here:
Attached is my code.
This is my error message:
Fatal error: Cannot access empty property in /home/frank/dev/www/cogiw2 008/newcla ss.php on line 32
I am trying to make a class that has classes. Is that possible and if so, what am I doing wrong here:
Attached is my code.
This is my error message:
Fatal error: Cannot access empty property in /home/frank/dev/www/cogiw2
<?php
// class declaration
class AMember
{
protected $var1;
protected $var2;
function loadclass($var1, $var2)
{
$this->var1=$var1;
$this->var2=$var2;
}
function display()
{
echo $this->var1."<br>";
echo $this->var2."<br>";
}
}
class aClass
{
protected $_aMemberClass;
protected $_aMemberVar;
function _construct()
{
echo "constructing<br>\n";
}
function loadAMemberClass($var1, $var2)
{
$this->$_aMemberClass =& new AMember();
$this->$_aMemberClass->loadclass($var1, $var2);
$this->$_aMemberVar = "Hi I\'m a membervar";
}
function display()
{
$this->$_aMemberClass->display();
echo $this->$_aMemberVar."<br>\n";
}
}
/// end of class declaration
$class =& new aClass();
$class->loadAMemberClass("This is var1 one of member class","This is var2 one of member class" );
$class->display();
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the eyes...