Hi,

Is this a bad thing to do have a class stored within another class?

I would also like to store an array of another class within a class. 

It seems to work apart from the fact that I can't reference an array of 
class directly.
ie
$test_array[0]->get();
This gives an error.


Example code.
-----------------------------------------------------
<?
class sub_level {
  var $testing = 0;
  function set_test($temp){
    $this->testing = $temp;
  }
  function get_test(){
    return $this->testing;    
  }
}

class top_level {
  var $testing = 0;
  var $sub_class = "";
  function set($temp){
    $this->testing = $test;
  }
  function get(){
    return $this->testing;    
  }
}

  $test = new sub_level;
  $top = new top_level;
  $top2 = new top_level;

  $top->sub_class = $test;

  $top2->sub_class = $test;

  $top->sub_class->set_test(50);
  $top2->sub_class->set_test(1000);
  $test_array[0] = $top;
  $test_array[1] = $top2;

  echo get_class($test_array[0])."<BR>";
  echo get_class($test_array[1])."<BR>";
  echo get_class($test_array[2])."<BR>";
    
  $temp = $test_array[1];
  echo get_class($temp->sub_class)."<BR>";
  echo "Booo - ".$temp->sub_class->get_test();

?>
---------------------------------


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to