Jump to content

Archived

This topic is now archived and is closed to further replies.

wolves

objects working togther

Recommended Posts

HI

[code]
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();
[/code]

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

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

why ?

Share this post


Link to post
Share on other sites
Are the PHP versions the same?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.