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/cogiw2008/newclass.php on line 32
<?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();
?>

Open in new window

ibanjaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NoiSCommented:
Some sintax error

__construct, not _construct

$this->_aMemberClass, not $this->$_aMemberClass

$this->_aMemberVar, not $this->$_aMemberVar

Don't need & before new

$class =new aClass();
$this->_aMemberClass =new AMember();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ibanjaAuthor Commented:
Yikes!!!

Thanks for the eyes...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.