Jump to content


Photo

objects working togther


  • Please log in to reply
1 reply to this topic

#1 wolves

wolves
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 19 April 2006 - 05:06 PM

HI

 class a {

   public $data;
  
   public function __construct($data) {
     this->data = $data;
  }

 } 
 
 class b {
   
   public $itens = Array();

   public function add_item($item) {
      
     $this->itens[] = new a($item);
  
   }

   public function get() {
   
     print_r($this->itens);
   }

 }

 class c {
   
   public $test = Array();
  
     public function &do_b() {
     
       $this->test = new b();
        return $this->test[sizeof($this->test)-1];
     
    }

    public function get() {
       foreach($test as $tt ) {
         $tt->get();
       }
    } 
 
 }

 }

  $test = new c;
  $bclass = $test->do_b(); 
  $bclass->add_item("hello");
  $bclass->add_item("hi");

   $test->get();

ok in my machine $test->get will print "hello", "hi" .....

but at my server it not works, it's print nothing "Array()"

why ?


#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 19 April 2006 - 06:54 PM

Are the PHP versions the same?

Info: PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users